@planeasyinc/le-angular 0.0.23 → 0.0.25

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.
@@ -23,7 +23,7 @@ import { FeFieldHost } from '@planeasyinc/fe-angular';
23
23
  import * as i1 from '@angular/forms';
24
24
  import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
25
25
 
26
- const IS_LIBRARY_REQUEST = new HttpContextToken(() => false);
26
+ const LE_REQUEST_CONTEXT_TOKEN = new HttpContextToken(() => false);
27
27
 
28
28
  const defaultConfig = {
29
29
  apiUrl: '',
@@ -87,7 +87,7 @@ class LEApiService {
87
87
  const url = new UrlFragmentBuilder(this.apiUrl())
88
88
  .setFragment('api/contrib/frontend-config/dashboard/config')
89
89
  .build();
90
- return this.http.get(url, { context: new HttpContext().set(IS_LIBRARY_REQUEST, true) });
90
+ return this.http.get(url, { context: new HttpContext().set(LE_REQUEST_CONTEXT_TOKEN, true) });
91
91
  }
92
92
  getObject(className, query = '') {
93
93
  const url = new UrlFragmentBuilder(this.apiUrl())
@@ -97,7 +97,7 @@ class LEApiService {
97
97
  .setQuery(query)
98
98
  .build();
99
99
  return this.http.get(url, {
100
- context: new HttpContext().set(IS_LIBRARY_REQUEST, true),
100
+ context: new HttpContext().set(LE_REQUEST_CONTEXT_TOKEN, true),
101
101
  });
102
102
  }
103
103
  getObjectByAddress(address, params) {
@@ -106,7 +106,7 @@ class LEApiService {
106
106
  .setQuery(`all_versions=${params.includeVersions ?? false}&include_metadata=${params.includeMeta ?? false}&load_references=${params.loadReferences ?? false}&file_optimized=${params.fileOptimized ?? true}`)
107
107
  .build();
108
108
  return this.http.get(url, {
109
- context: new HttpContext().set(IS_LIBRARY_REQUEST, true),
109
+ context: new HttpContext().set(LE_REQUEST_CONTEXT_TOKEN, true),
110
110
  });
111
111
  }
112
112
  executeTransaction(name, body, query = '') {
@@ -115,20 +115,20 @@ class LEApiService {
115
115
  .setQuery(query)
116
116
  .build();
117
117
  return this.http.post(url, body ?? {}, {
118
- context: new HttpContext().set(IS_LIBRARY_REQUEST, true),
118
+ context: new HttpContext().set(LE_REQUEST_CONTEXT_TOKEN, true),
119
119
  });
120
120
  }
121
121
  request(method, path, body) {
122
122
  const url = new UrlFragmentBuilder(this.apiUrl()).setFragment(path).build();
123
123
  const request = new HttpRequest(method, url, body, {
124
124
  responseType: 'json',
125
- context: new HttpContext().set(IS_LIBRARY_REQUEST, true),
125
+ context: new HttpContext().set(LE_REQUEST_CONTEXT_TOKEN, true),
126
126
  });
127
127
  return this.http.request(request);
128
128
  }
129
129
  getBlob(path) {
130
130
  return this.http
131
- .get(path, { responseType: 'blob', context: new HttpContext().set(IS_LIBRARY_REQUEST, true) })
131
+ .get(path, { responseType: 'blob', context: new HttpContext().set(LE_REQUEST_CONTEXT_TOKEN, true) })
132
132
  .pipe(map((blob) => URL.createObjectURL(blob)));
133
133
  }
134
134
  normalizeApiUrl(url) {
@@ -257,7 +257,7 @@ class LEDataService {
257
257
  navigateByNodeId(id) {
258
258
  const node = this.getNodeById(id);
259
259
  if (node) {
260
- this._view.set(node);
260
+ this.setView(node);
261
261
  }
262
262
  }
263
263
  getNodeById(id, node = this._config()) {
@@ -447,12 +447,22 @@ const info = {
447
447
  ],
448
448
  };
449
449
 
450
+ const download$1 = {
451
+ name: 'download',
452
+ viewBox: '0 -960 960 960',
453
+ content: [
454
+ 'M480-320 280-520l56-58 104 104v-326h80v326l104-104 56 58-200 200ZM240-160q-33 0-56.5-23.5T160-240v-120h80v120h480v-120h80v120q0 33-23.5 56.5T720-160H240Z',
455
+ ],
456
+ };
457
+ // <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M480-320 280-520l56-58 104 104v-326h80v326l104-104 56 58-200 200ZM240-160q-33 0-56.5-23.5T160-240v-120h80v120h480v-120h80v120q0 33-23.5 56.5T720-160H240Z"/></svg>
458
+
450
459
  const ICONS_MAP = {
451
460
  chevron: chevron,
452
461
  'arrow-down': arrowDown,
453
462
  sort: sort,
454
463
  close: close,
455
- info: info
464
+ info: info,
465
+ download: download$1,
456
466
  };
457
467
 
458
468
  class LeIconComponent {
@@ -653,10 +663,21 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImpo
653
663
  ], changeDetection: ChangeDetectionStrategy.OnPush, template: "<cdk-tree [dataSource]=\"source()\" [treeControl]=\"treeControl\">\n <!-- Tree node template for leaf nodes -->\n <cdk-nested-tree-node *cdkTreeNodeDef=\"let node\" class=\"le-tree-node\">\n <div class=\"le-tree-row\">\n <b>{{node.label | uppercase}}</b>: &nbsp;&nbsp;&nbsp; {{node.value}}\n </div>\n </cdk-nested-tree-node>\n\n <!-- Tree node template for expandable nodes -->\n <cdk-nested-tree-node *cdkTreeNodeDef=\"let node; when: hasChild\" class=\"le-tree-node\">\n\n <a class=\"le-tree-row\" [class.le-tree-row--expanded]=\"treeControl.isExpanded(node)\" [attr.aria-label]=\"'Toggle ' + node.label\" cdkTreeNodeToggle>\n <b>{{node.label | uppercase}}</b>:\n\n <le-icon class=\"le-tree-chevron\" name=\"chevron\"></le-icon>\n </a>\n\n <div [class.le-tree-invisible]=\"!treeControl.isExpanded(node)\">\n <ng-container cdkTreeNodeOutlet></ng-container>\n </div>\n </cdk-nested-tree-node>\n</cdk-tree>\n" }]
654
664
  }] });
655
665
 
656
- class StringTemplate {
666
+ class BaseTemplate {
657
667
  data = input.required();
658
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: StringTemplate, deps: [], target: i0.ɵɵFactoryTarget.Component });
659
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.2.21", type: StringTemplate, isStandalone: true, selector: "ng-component", inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: `<span class="le-table-template le-template-string">{{ data() ?? '–' }}</span>`, isInline: true });
668
+ attribute = input.required();
669
+ metadata = input.required();
670
+ clicked = output();
671
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: BaseTemplate, deps: [], target: i0.ɵɵFactoryTarget.Directive });
672
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.21", type: BaseTemplate, isStandalone: true, inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: true, transformFunction: null }, attribute: { classPropertyName: "attribute", publicName: "attribute", isSignal: true, isRequired: true, transformFunction: null }, metadata: { classPropertyName: "metadata", publicName: "metadata", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { clicked: "clicked" }, ngImport: i0 });
673
+ }
674
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: BaseTemplate, decorators: [{
675
+ type: Directive
676
+ }] });
677
+
678
+ class StringTemplate extends BaseTemplate {
679
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: StringTemplate, deps: null, target: i0.ɵɵFactoryTarget.Component });
680
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.21", type: StringTemplate, isStandalone: true, selector: "ng-component", usesInheritance: true, ngImport: i0, template: `<span class="le-table-template le-template-string">{{ data() ?? '–' }}</span>`, isInline: true });
660
681
  }
661
682
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: StringTemplate, decorators: [{
662
683
  type: Component,
@@ -665,11 +686,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImpo
665
686
  }]
666
687
  }] });
667
688
 
668
- class ReferenceTemplate {
669
- data = input.required();
670
- attribute = input.required();
671
- metadata = input.required();
672
- clicked = output();
689
+ class ReferenceTemplate extends BaseTemplate {
673
690
  reference = computed(() => {
674
691
  const ref = this.data()?.ref;
675
692
  return {
@@ -680,7 +697,10 @@ class ReferenceTemplate {
680
697
  onClick(event) {
681
698
  event.preventDefault();
682
699
  event.stopImmediatePropagation();
683
- this.clicked.emit(this.data());
700
+ this.clicked.emit({
701
+ type: 'reference',
702
+ data: this.data(),
703
+ });
684
704
  }
685
705
  generateText(ref) {
686
706
  if (ref) {
@@ -695,8 +715,8 @@ class ReferenceTemplate {
695
715
  return ref?.address ? `${href}?address=${ref.address}` : href;
696
716
  }
697
717
  }
698
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: ReferenceTemplate, deps: [], target: i0.ɵɵFactoryTarget.Component });
699
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.21", type: ReferenceTemplate, isStandalone: true, selector: "ng-component", inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: true, transformFunction: null }, attribute: { classPropertyName: "attribute", publicName: "attribute", isSignal: true, isRequired: true, transformFunction: null }, metadata: { classPropertyName: "metadata", publicName: "metadata", isSignal: true, isRequired: true, transformFunction: null } }, outputs: { clicked: "clicked" }, ngImport: i0, template: `
718
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: ReferenceTemplate, deps: null, target: i0.ɵɵFactoryTarget.Component });
719
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.21", type: ReferenceTemplate, isStandalone: true, selector: "ng-component", usesInheritance: true, ngImport: i0, template: `
700
720
  <span class="le-table-template le-template-reference">
701
721
  @if (reference(); as reference) {
702
722
  @if (reference.href) {
@@ -737,10 +757,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImpo
737
757
  }]
738
758
  }] });
739
759
 
740
- class JSONTemplate {
741
- data = input.required();
742
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: JSONTemplate, deps: [], target: i0.ɵɵFactoryTarget.Component });
743
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.2.21", type: JSONTemplate, isStandalone: true, selector: "ng-component", inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: `<pre class="le-table-template le-template-json">{{
760
+ class JSONTemplate extends BaseTemplate {
761
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: JSONTemplate, deps: null, target: i0.ɵɵFactoryTarget.Component });
762
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.21", type: JSONTemplate, isStandalone: true, selector: "ng-component", usesInheritance: true, ngImport: i0, template: `<pre class="le-table-template le-template-json">{{
744
763
  data() ? (data() | json) : '–'
745
764
  }}</pre>`, isInline: true, dependencies: [{ kind: "pipe", type: JsonPipe, name: "json" }] });
746
765
  }
@@ -754,15 +773,60 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImpo
754
773
  }]
755
774
  }] });
756
775
 
776
+ class FileTemplate extends BaseTemplate {
777
+ onClick(event) {
778
+ event.preventDefault();
779
+ event.stopImmediatePropagation();
780
+ this.clicked.emit({
781
+ type: 'file',
782
+ data: this.data(),
783
+ });
784
+ }
785
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: FileTemplate, deps: null, target: i0.ɵɵFactoryTarget.Component });
786
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.21", type: FileTemplate, isStandalone: true, selector: "ng-component", usesInheritance: true, ngImport: i0, template: `
787
+ <span class="le-table-template le-template-file">
788
+ @if (data()) {
789
+ <a [attr.aria-label]="'Download'" (click)="onClick($event)">
790
+ <le-icon size="16" class="le-icon-download" name="download"></le-icon>
791
+ Download
792
+ </a>
793
+ } @else {
794
+ No file attached
795
+ }
796
+ </span>
797
+ `, isInline: true, dependencies: [{ kind: "component", type: LeIconComponent, selector: "le-icon", inputs: ["name", "size"] }] });
798
+ }
799
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.21", ngImport: i0, type: FileTemplate, decorators: [{
800
+ type: Component,
801
+ args: [{
802
+ standalone: true,
803
+ imports: [LeIconComponent],
804
+ template: `
805
+ <span class="le-table-template le-template-file">
806
+ @if (data()) {
807
+ <a [attr.aria-label]="'Download'" (click)="onClick($event)">
808
+ <le-icon size="16" class="le-icon-download" name="download"></le-icon>
809
+ Download
810
+ </a>
811
+ } @else {
812
+ No file attached
813
+ }
814
+ </span>
815
+ `,
816
+ }]
817
+ }] });
818
+
757
819
  const TABLE_SELL_TEMPLATE_NAMES = {
758
820
  StringTemplate: 'StringTemplate',
759
821
  ReferenceTemplate: 'ReferenceTemplate',
760
822
  JsonTemplate: 'JsonTemplate',
823
+ FileTemplate: 'FileTemplate',
761
824
  };
762
825
  const TABLE_CELL_TEMPLATES = {
763
826
  StringTemplate: StringTemplate,
764
827
  ReferenceTemplate: ReferenceTemplate,
765
828
  JsonTemplate: JSONTemplate,
829
+ FileTemplate: FileTemplate,
766
830
  };
767
831
 
768
832
  class TableViewCellDirective {
@@ -789,18 +853,16 @@ class TableViewCellDirective {
789
853
  }
790
854
  this.componentRef = this.vcr.createComponent(component);
791
855
  this.componentRef?.setInput('data', data);
792
- if (type === 'ReferenceTemplate') {
793
- if (column) {
794
- this.componentRef?.setInput('attribute', column);
795
- }
796
- if (metadata) {
797
- this.componentRef?.setInput('metadata', metadata);
798
- }
799
- const sub = (this.componentRef?.instance).clicked.subscribe(data => {
800
- this.clicked.emit(data);
801
- });
802
- this.componentRef?.onDestroy(() => sub.unsubscribe());
856
+ if (column) {
857
+ this.componentRef?.setInput('attribute', column);
858
+ }
859
+ if (metadata) {
860
+ this.componentRef?.setInput('metadata', metadata);
803
861
  }
862
+ const sub = (this.componentRef?.instance).clicked.subscribe(data => {
863
+ this.clicked.emit(data);
864
+ });
865
+ this.componentRef?.onDestroy(() => sub.unsubscribe());
804
866
  });
805
867
  });
806
868
  }
@@ -1224,6 +1286,15 @@ const buildQueryString = (params) => {
1224
1286
  return query.filter((item) => !!item).join('&');
1225
1287
  };
1226
1288
 
1289
+ const download = (url) => {
1290
+ const a = document.createElement('a');
1291
+ a.style.display = 'none';
1292
+ a.href = url;
1293
+ document.body.appendChild(a);
1294
+ a.click();
1295
+ window.URL.revokeObjectURL(url);
1296
+ };
1297
+
1227
1298
  class TableViewComponent {
1228
1299
  apiService = inject(LEApiService);
1229
1300
  dataService = inject(LEDataService);
@@ -1359,16 +1430,42 @@ class TableViewComponent {
1359
1430
  });
1360
1431
  }
1361
1432
  onCellClicked(data) {
1362
- const path = `${data.ref.resource}%23${data.ref.class_name}%3A${data.ref.class_version}%3A${data.ref.object_id}%3A${data.ref.object_version}`;
1433
+ if (data.type === 'reference') {
1434
+ this.processReferenceClick(data.data);
1435
+ }
1436
+ else if (data.type === 'file') {
1437
+ this.processFileClick(data.data);
1438
+ }
1439
+ }
1440
+ processReferenceClick(data) {
1441
+ const address = this.getAddressFromRef(data.ref);
1363
1442
  this.setView({
1364
- id: path,
1443
+ id: address,
1365
1444
  type: 'form',
1366
1445
  controlSource: {
1367
1446
  kind: 'object',
1368
- entity: path,
1447
+ entity: address,
1369
1448
  },
1370
1449
  });
1371
1450
  }
1451
+ processFileClick(data) {
1452
+ console.log('processFileClick', data);
1453
+ const ref = data.ref || data;
1454
+ if (ref && 'resource' in ref) {
1455
+ const address = this.getAddressFromRef(ref);
1456
+ this.apiService.getObjectByAddress(address, {}).subscribe({
1457
+ next: (res) => {
1458
+ download(res.rows[0].data);
1459
+ },
1460
+ });
1461
+ }
1462
+ else if (typeof ref === 'string') {
1463
+ download(ref);
1464
+ }
1465
+ }
1466
+ getAddressFromRef(ref) {
1467
+ return `${ref.resource}%23${ref.class_name}%3A${ref.class_version}%3A${ref.object_id}%3A${ref.object_version}`;
1468
+ }
1372
1469
  processRowClickAction(action, row) {
1373
1470
  const { type, node } = action;
1374
1471
  const clone = JSON.parse(JSON.stringify(node));
@@ -2774,7 +2871,7 @@ const LEAuthInterceptor = (req, next) => {
2774
2871
  if (authService.isGuest()) {
2775
2872
  return next(req);
2776
2873
  }
2777
- if (req.context.get(IS_LIBRARY_REQUEST)) {
2874
+ if (req.context.get(LE_REQUEST_CONTEXT_TOKEN)) {
2778
2875
  try {
2779
2876
  authService.validateToken();
2780
2877
  return next(req.clone({ setHeaders: { Authorization: authService.token() } }));
@@ -2791,5 +2888,5 @@ const LEAuthInterceptor = (req, next) => {
2791
2888
  * Generated bundle index. Do not edit.
2792
2889
  */
2793
2890
 
2794
- export { CONFIG_TOKEN, LEAuthInterceptor, LEAuthService, LeContainerComponent, LeToastService, provideConfig };
2891
+ export { CONFIG_TOKEN, LEAuthInterceptor, LEAuthService, CONFIG_TOKEN as LE_CONFIG_TOKEN, LE_REQUEST_CONTEXT_TOKEN, LeContainerComponent, LeToastService, provideConfig };
2795
2892
  //# sourceMappingURL=planeasyinc-le-angular.mjs.map