@c8y/tutorial 1019.13.5 → 1019.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { EnvironmentOptions } from '@c8y/devkit/dist/options';
1
+ import { ConfigurationOptions } from '@c8y/devkit/dist/options';
2
2
  import { DefinePlugin } from 'webpack';
3
3
  import { author, description, version } from './package.json';
4
4
 
@@ -454,6 +454,12 @@ export default {
454
454
  path: './src/help/help-example.module.ts',
455
455
  description: 'An example for help.'
456
456
  },
457
+ {
458
+ name: 'Example of extendable input list',
459
+ module: 'ExtendableInputListExampleModule',
460
+ path: './src/input-group/extendable-input-list-example.module.ts',
461
+ description: 'An example for extendable input list.'
462
+ },
457
463
  {
458
464
  name: 'Example of time picker',
459
465
  module: 'TimePickerExampleModule',
@@ -675,6 +681,7 @@ export default {
675
681
  'RealtimeTutorialModule',
676
682
  'ProviderConfigurationTutorialModule',
677
683
  'HelpExampleModule',
684
+ 'ExtendableInputListExampleModule',
678
685
  'TimePickerExampleModule',
679
686
  'DateTimeRangeExampleModule',
680
687
  'DatapointSelectionListExampleModule',
@@ -733,4 +740,4 @@ export default {
733
740
  '@ngx-formly/core'
734
741
  ]
735
742
  }
736
- } as const satisfies EnvironmentOptions;
743
+ } as const satisfies ConfigurationOptions;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@c8y/tutorial",
3
- "version": "1019.13.5",
3
+ "version": "1019.18.0",
4
4
  "description": "This package is used to scaffold a tutorial for Cumulocity IoT Web SDK which explains a lot of concepts.",
5
5
  "dependencies": {
6
- "@c8y/devkit": "1019.13.5",
7
- "@c8y/style": "1019.13.5",
8
- "@c8y/ngx-components": "1019.13.5",
9
- "@c8y/client": "1019.13.5",
10
- "@c8y/bootstrap": "1019.13.5",
6
+ "@c8y/devkit": "1019.18.0",
7
+ "@c8y/style": "1019.18.0",
8
+ "@c8y/ngx-components": "1019.18.0",
9
+ "@c8y/client": "1019.18.0",
10
+ "@c8y/bootstrap": "1019.18.0",
11
11
  "@angular/cdk": "^16.2.11",
12
12
  "ngx-bootstrap": "11.0.2",
13
13
  "leaflet": "1.7.1",
@@ -13,7 +13,6 @@ import { DateTimePickerModule } from '@c8y/ngx-components';
13
13
  <label class="m-r-sm-8">{{ 'Range' | translate }}</label>
14
14
  <div
15
15
  class="dropdown m-r-4 m-t-xs-4 m-b-xs-4"
16
- container="body"
17
16
  #dropdown="bs-dropdown"
18
17
  dropdown
19
18
  [insideClick]="true"
@@ -28,6 +28,7 @@ import { CoreModule } from '@c8y/ngx-components';
28
28
  <li><a href="#/grids/client-grid-example">Grid</a></li>
29
29
  <li><a href="#/css">Styles</a></li>
30
30
  <li><a href="#/input">Input</a></li>
31
+ <li><a href="#/extendable-input-list">Extendable input list example</a></li>
31
32
  <li><a href="#/maps/simple">Maps</a></li>
32
33
  <li><a href="#/translations/text-translation/service-translation">Translations</a></li>
33
34
  <li><a href="#/realtime">Realtime</a></li>
@@ -1,13 +1,27 @@
1
1
  import { Component, OnInit } from '@angular/core';
2
2
  import { SetupStep, StepperService, Steppers } from '@c8y/ngx-components';
3
+ import { firstValueFrom } from 'rxjs';
3
4
 
4
5
  /**
5
6
  * This is a standard angular component.
6
- * Obviously it does not do anything.
7
7
  */
8
8
  @Component({
9
9
  selector: 'tut-basic-stepper-hook-view',
10
- templateUrl: './basic-view.component.html'
10
+ template: `
11
+ <c8y-title>Stepper</c8y-title>
12
+ <div class="card">
13
+ <div class="card-block">
14
+ <p>This is the example of <code>hookStepper</code>.</p>
15
+ <div class="container-fluid" *ngIf="this.steps?.length > 0">
16
+ <c8y-stepper-outlet
17
+ class="d-contents"
18
+ [showDefaultButtons]="false"
19
+ [steps]="steps"
20
+ ></c8y-stepper-outlet>
21
+ </div>
22
+ </div>
23
+ </div>
24
+ `
11
25
  })
12
26
  export class BasicViewComponent implements OnInit {
13
27
  readonly stepperId = Steppers.SETUP;
@@ -20,7 +34,8 @@ export class BasicViewComponent implements OnInit {
20
34
  constructor(private stepperService: StepperService) {}
21
35
 
22
36
  async ngOnInit(): Promise<void> {
23
- this.steps = (await this.stepperService.getById$('test').toPromise()).map(
37
+ const stepsId = 'example'; // `example` is a stepperId value for both steps
38
+ this.steps = (await firstValueFrom(this.stepperService.getById$(stepsId))).map(
24
39
  (step: SetupStep, index) => ({
25
40
  ...step,
26
41
  index,
@@ -30,7 +30,7 @@ const routes: Routes = [
30
30
  }),
31
31
  hookStepper([
32
32
  {
33
- stepperId: 'test',
33
+ stepperId: 'example',
34
34
  component: Step1Component,
35
35
  label: 'Step 1',
36
36
  setupId: 'step1',
@@ -39,7 +39,7 @@ const routes: Routes = [
39
39
  injector: null
40
40
  },
41
41
  {
42
- stepperId: 'test',
42
+ stepperId: 'example',
43
43
  component: Step2Component,
44
44
  label: 'Step 2',
45
45
  setupId: 'step2',
@@ -1,18 +1,43 @@
1
+ import { CdkStep } from '@angular/cdk/stepper';
1
2
  import { Component, OnInit } from '@angular/core';
2
3
  import { FormBuilder, FormGroup, Validators } from '@angular/forms';
4
+ import { C8yStepper } from '@c8y/ngx-components';
3
5
 
4
6
  @Component({
5
7
  selector: 'tut-step-1-device',
6
- templateUrl: './step1.component.html'
8
+ template: `
9
+ <div class="m-l-40 m-r-40 m-t-32">
10
+ <h4 class="p-b-8" title="Device name">Enter the device name</h4>
11
+ <c8y-form-group>
12
+ <div [formGroup]="formGroupStepOne">
13
+ <input class="form-control" placeholder="MyDevice" type="text" formControlName="name" />
14
+ <c8y-messages>
15
+ <c8y-message [text]="'Enter the name of the Device'"></c8y-message>
16
+ </c8y-messages>
17
+ </div>
18
+ </c8y-form-group>
19
+ <c8y-stepper-buttons
20
+ [showButtons]="{ next: true, cancel: false, back: false, custom: false }"
21
+ [disabled]="!formGroupStepOne.valid"
22
+ (onNext)="goToNextStep($event)"
23
+ ></c8y-stepper-buttons>
24
+ </div>
25
+ `
7
26
  })
8
27
  export class Step1Component implements OnInit {
9
28
  formGroupStepOne: FormGroup;
10
29
 
11
30
  constructor(private fb: FormBuilder) {}
12
31
 
13
- ngOnInit() {
32
+ ngOnInit(): void {
14
33
  this.formGroupStepOne = this.fb.group({
15
34
  name: ['', Validators.required]
16
35
  });
17
36
  }
37
+
38
+ goToNextStep(event: { stepper: C8yStepper; step: CdkStep }): void {
39
+ console.log('My device name is: ' + this.formGroupStepOne.get('name').value);
40
+ this.formGroupStepOne.reset();
41
+ event.stepper.next();
42
+ }
18
43
  }
@@ -2,7 +2,15 @@ import { Component } from '@angular/core';
2
2
 
3
3
  @Component({
4
4
  selector: 'tut-step-2-device',
5
- templateUrl: './step2.component.html'
5
+ template: `
6
+ <div class="m-l-40 m-r-40 m-t-32">
7
+ <h4 class="p-b-32 text-center">Your device is now ready to save the world!</h4>
8
+ </div>
9
+ <c8y-stepper-buttons
10
+ [showButtons]="{ next: false, cancel: false, back: true, custom: false }"
11
+ [labels]="{ back: 'Got it!' }"
12
+ ></c8y-stepper-buttons>
13
+ `
6
14
  })
7
15
  export class Step2Component {
8
16
  close() {
@@ -0,0 +1,51 @@
1
+ import { CommonModule } from '@angular/common';
2
+ import { Component } from '@angular/core';
3
+ import { CoreModule, FormsModule } from '@c8y/ngx-components';
4
+
5
+ @Component({
6
+ selector: 'c8y-extendable-input-list-example',
7
+ template: `<c8y-title>Extendable input list Example</c8y-title>
8
+ <div class="container-fluid p-24">
9
+ <ul class="list-unstyled p-t-16" c8yInputGroupListContainer>
10
+ <li class="m-b-8" *ngFor="let item of items; let i = index; trackBy: trackByFn">
11
+ <c8y-input-group-list
12
+ [index]="i"
13
+ (onAdd)="add()"
14
+ (onRemove)="remove($event)"
15
+ [minus]="items.length > 1"
16
+ >
17
+ <c8y-form-group class="form-group--tooltip-validation">
18
+ <input
19
+ class="form-control"
20
+ placeholder="{{ 'e.g.' }} placeholder"
21
+ type="text"
22
+ [required]="true"
23
+ [(ngModel)]="items[i]"
24
+ />
25
+ </c8y-form-group>
26
+ </c8y-input-group-list>
27
+ </li>
28
+ </ul>
29
+ </div>`,
30
+ standalone: true,
31
+ imports: [CoreModule, FormsModule, CommonModule]
32
+ })
33
+ export class ExtendableInputListExampleComponent {
34
+ items: string[] = [];
35
+
36
+ ngOnInit() {
37
+ this.add();
38
+ }
39
+
40
+ trackByFn(index: any, _item: any) {
41
+ return index;
42
+ }
43
+
44
+ add() {
45
+ this.items.push('');
46
+ }
47
+
48
+ remove(index) {
49
+ this.items.splice(index, 1);
50
+ }
51
+ }
@@ -0,0 +1,25 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { NavigatorNode, hookNavigator, hookRoute } from '@c8y/ngx-components';
4
+
5
+ @NgModule({
6
+ imports: [CommonModule],
7
+ providers: [
8
+ hookRoute({
9
+ path: 'extendable-input-list',
10
+ loadComponent: () =>
11
+ import('./extendable-input-list-example.component').then(
12
+ m => m.ExtendableInputListExampleComponent
13
+ )
14
+ }),
15
+ hookNavigator(
16
+ new NavigatorNode({
17
+ path: '/extendable-input-list',
18
+ label: 'Extendable input list',
19
+ icon: 'hand-o-right',
20
+ priority: 5
21
+ })
22
+ )
23
+ ]
24
+ })
25
+ export class ExtendableInputListExampleModule {}
@@ -39,13 +39,11 @@ import { IIdentified } from '@c8y/client';
39
39
  <p class="text-medium p-t-8">Preview</p>
40
40
  <div class="card m-t-16">
41
41
  <div class="card-block d-flex d-col p-0" style="height: 540px">
42
- <!-- important -->
43
42
  <c8y-asset-selector-miller
44
43
  [(ngModel)]="model"
45
44
  (onSelected)="selectionChanged($event)"
46
45
  [config]="config"
47
46
  ></c8y-asset-selector-miller>
48
- <!-- /important -->
49
47
  </div>
50
48
  </div>
51
49
  </ng-container>
@@ -39,14 +39,12 @@ import { IIdentified } from '@c8y/client';
39
39
  <p class="text-medium p-t-8">Preview</p>
40
40
  <div class="card m-t-16">
41
41
  <div class="card-block p-0 bg-inherit" style="height: 428px">
42
- <!-- important -->
43
42
  <c8y-asset-selector
44
43
  class="bg-inherit"
45
44
  [(ngModel)]="model"
46
45
  (onSelected)="selectionChanged($event)"
47
46
  [config]="config"
48
47
  ></c8y-asset-selector>
49
- <!-- /important -->
50
48
  </div>
51
49
  </div>
52
50
  </ng-container>
@@ -18,29 +18,29 @@ enum step {
18
18
  THIRD = 2
19
19
  }
20
20
  @Component({
21
- selector: 'c8y-stepper-device',
21
+ selector: 'tut-device-stepper',
22
22
  templateUrl: './device-stepper.component.html',
23
23
  standalone: true,
24
24
  imports: [CoreModule, FormsModule, ReactiveFormsModule]
25
25
  })
26
26
  export class DeviceStepperComponent implements OnInit {
27
+ @ViewChild(C8yStepper, { static: true })
28
+ private stepper: C8yStepper;
29
+
27
30
  formGroupStepOne: FormGroup;
28
31
  formGroupStepTwo: FormGroup;
29
-
32
+ isModal: boolean;
30
33
  pendingStatus = false;
31
34
 
32
- @ViewChild(C8yStepper, { static: true })
33
- stepper: C8yStepper;
34
- isModal: boolean;
35
+ private onClose: Subject<void> = new Subject();
35
36
 
36
- private onClose: Subject<any> = new Subject();
37
37
  constructor(
38
38
  private fb: FormBuilder,
39
39
  private stepperService: StepperService,
40
40
  private bsModalRef: BsModalRef
41
41
  ) {}
42
42
 
43
- ngOnInit() {
43
+ ngOnInit(): void {
44
44
  this.formGroupStepOne = this.fb.group({
45
45
  name: ['', Validators.required]
46
46
  });
@@ -50,31 +50,33 @@ export class DeviceStepperComponent implements OnInit {
50
50
  });
51
51
  }
52
52
 
53
- navigate(clickedStepIDX: number) {
53
+ navigate(clickedStepIDX: number): void {
54
54
  console.log('Index is: ', clickedStepIDX);
55
55
  }
56
56
 
57
- onMovingForward(clickedStepIDX: number, selectedStepIDX: number) {
57
+ onMovingForward(clickedStepIDX: number, selectedStepIDX: number): void {
58
58
  this.stepper.next();
59
59
  if (clickedStepIDX === step.THIRD && selectedStepIDX === step.SECOND) {
60
60
  this.save();
61
61
  }
62
62
  }
63
- onMovingBackward(clickedStepIDX: number, selectedStepIDX: number) {
63
+
64
+ onMovingBackward(clickedStepIDX: number, selectedStepIDX: number): void {
64
65
  if ((clickedStepIDX === step.FIRST || step.SECOND) && selectedStepIDX === step.THIRD) {
65
66
  this.resetStepper();
66
67
  } else if (clickedStepIDX === step.FIRST && selectedStepIDX === step.SECOND) {
67
68
  this.stepper.previous();
68
69
  }
69
70
  }
70
- async save() {
71
+
72
+ async save(): Promise<void> {
71
73
  this.pendingStatus = true;
72
74
  await this.addDevice();
73
75
  this.pendingStatus = false;
74
76
  this.stepper.next();
75
77
  }
76
78
 
77
- close(isModal: boolean) {
79
+ close(isModal: boolean): void {
78
80
  if (isModal) {
79
81
  this.onClose.next(null);
80
82
  this.bsModalRef.hide();
@@ -83,7 +85,7 @@ export class DeviceStepperComponent implements OnInit {
83
85
  }
84
86
  }
85
87
 
86
- private async addDevice() {
88
+ private async addDevice(): Promise<void> {
87
89
  await this.stepperService.addDevice({
88
90
  id: Math.random() * 1000,
89
91
  name: upperFirst(this.formGroupStepOne.get('name').value),
@@ -91,7 +93,7 @@ export class DeviceStepperComponent implements OnInit {
91
93
  });
92
94
  }
93
95
 
94
- private resetStepper() {
96
+ private resetStepper(): void {
95
97
  this.stepper.reset();
96
98
  this.stepper.selectedIndex = 1;
97
99
  }
@@ -3,16 +3,18 @@ import { HeaderModule } from '@c8y/ngx-components';
3
3
  import { DeviceStepperComponent } from './device-stepper.component';
4
4
 
5
5
  @Component({
6
- selector: 'stepper',
7
- template: `<c8y-title>Stepper</c8y-title>
6
+ selector: 'tut-stepper',
7
+ template: `<div class="p-t-16">
8
+ <c8y-title>Stepper</c8y-title>
8
9
  <div class="card">
9
10
  <div class="card-header separator">
10
11
  <h4 class="card-title">Create new device</h4>
11
12
  </div>
12
13
  <div class="card-block">
13
- <c8y-stepper-device></c8y-stepper-device>
14
+ <tut-device-stepper></tut-device-stepper>
14
15
  </div>
15
- </div> `,
16
+ </div>
17
+ </div> `,
16
18
  standalone: true,
17
19
  imports: [HeaderModule, DeviceStepperComponent]
18
20
  })
@@ -1,17 +0,0 @@
1
- <!-- The c8y-title component will display the given string (here: "Stepper hook example") in the header as title -->
2
- <c8y-title>Stepper</c8y-title>
3
- <div class="card">
4
- <div class="card-block">
5
- <p>This is the example of <code>hookStepper</code>.</p>
6
- <div
7
- class="container-fluid"
8
- *ngIf="this.steps?.length > 0"
9
- >
10
- <c8y-stepper-outlet
11
- class="d-contents"
12
- [showDefaultButtons]="false"
13
- [steps]="steps"
14
- ></c8y-stepper-outlet>
15
- </div>
16
- </div>
17
- </div>
@@ -1,24 +0,0 @@
1
- <div class="m-l-40 m-r-40 m-t-32">
2
- <h4
3
- class="p-b-8"
4
- title="Device name"
5
- >
6
- Enter the device name
7
- </h4>
8
- <c8y-form-group>
9
- <div [formGroup]="formGroupStepOne">
10
- <input
11
- class="form-control"
12
- placeholder="MyDevice"
13
- type="text"
14
- formControlName="name"
15
- />
16
- <c8y-messages>
17
- <c8y-message [text]="'Enter the name of the Device'"></c8y-message>
18
- </c8y-messages>
19
- </div>
20
- </c8y-form-group>
21
- </div>
22
- <c8y-stepper-buttons
23
- [showButtons]="{ next: true, cancel: false, back: false, custom: false }"
24
- ></c8y-stepper-buttons>
@@ -1,7 +0,0 @@
1
- <div class="m-l-40 m-r-40 m-t-32">
2
- <h4 class="p-b-32 text-center">Your device is now ready to save the world!</h4>
3
- </div>
4
- <c8y-stepper-buttons
5
- [showButtons]="{ next: false, cancel: false, back: true, custom: false }"
6
- [labels]="{ back: 'Got it!' }"
7
- ></c8y-stepper-buttons>