Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class DfApiDocsTableComponent extends DfManageTableComponent<ApiDocsRowDa
}

override mapDataToTable(data: Service[]): ApiDocsRowData[] {
const sortedData = data.sort((a, b) => a.id - b.id);
const sortedData = data.sort((a, b) => a.name.localeCompare(b.name));
return sortedData.map(val => {
const type = this.getServiceType(val.type);
return {
Expand All @@ -114,7 +114,7 @@ export class DfApiDocsTableComponent extends DfManageTableComponent<ApiDocsRowDa
): void {
this.servicesService
.getAll<GenericListResponse<Service>>({
limit,
limit: 100 || limit,
offset,
filter: `(type not like "%swagger%")${filter ? ` and ${filter}` : ''}`,
})
Expand Down
10 changes: 10 additions & 0 deletions src/app/adf-api-docs/df-api-docs/df-api-docs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export class DfApiDocsComponent implements OnInit, AfterContentInit {
domNode: this.apiDocElement?.nativeElement,
requestInterceptor: (req: SwaggerUI.Request) => {
req['headers'][SESSION_TOKEN_HEADER] = this.userDataService.token;
// Parse the request URL
const url = new URL(req['url']);
const params = new URLSearchParams(url.search);
// Decode all parameters
params.forEach((value, key) => {
params.set(key, decodeURIComponent(value));
});
// Update the URL with decoded parameters
url.search = params.toString();
req['url'] = url.toString();
return req;
},
showMutatedRequest: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ <h4 class="text-center" style="color: black !important">
<mat-accordion class="full-width">
<mat-expansion-panel [expanded]="serviceForm.getRawValue().type">
<mat-expansion-panel-header
>{{ 'services.options' | transloco }}s
>{{ 'services.options' | transloco }}
</mat-expansion-panel-header>
<div class="details-section">
<ng-container *ngIf="this.isNetworkService">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ export class DfServiceDetailsComponent implements OnInit {
return;
}
const data = this.serviceForm.getRawValue();
data.service_doc_by_service_id.content = this.serviceDefinition;
data.service_doc_by_service_id.format = Number(this.serviceDefinitionType);

type Params = {
snackbarError: string;
snackbarSuccess: string;
Expand All @@ -304,6 +303,12 @@ export class DfServiceDetailsComponent implements OnInit {
fields: '*',
related: 'service_doc_by_service_id',
};
data.service_doc_by_service_id.content = this.serviceDefinition;
data.service_doc_by_service_id.format = Number(
this.serviceDefinitionType
);
} else {
delete data.service_doc_by_service_id; // Remove service_doc_by_service_id if it's not a network service
}

if (this.edit) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export const routes: Routes = [
'./adf-api-docs/df-api-docs/df-api-docs-table.component'
).then(m => m.DfApiDocsTableComponent),
resolve: {
data: servicesResolver(10, '(type not like "%swagger%")'),
data: servicesResolver(100, '(type not like "%swagger%")'),
serviceTypes: serviceTypesResolver,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {
OnInit,
ViewChild,
} from '@angular/core';
import { MatPaginatorModule, PageEvent } from '@angular/material/paginator';
import {
MatPaginator,
MatPaginatorModule,
PageEvent,
} from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
import { ActivatedRoute, Router } from '@angular/router';
Expand Down Expand Up @@ -81,6 +85,7 @@ export abstract class DfManageTableComponent<T>
abstract columns: Array<Column<T>>;

@ViewChild(MatSort) sort: MatSort;
@ViewChild(MatPaginator) paginator: MatPaginator;
_activatedRoute = this.activatedRoute;
_translateService = this.translateService;

Expand Down Expand Up @@ -123,6 +128,7 @@ export abstract class DfManageTableComponent<T>
this.schema = this.router.url.includes('schema');
if (data && data.resource) {
this.dataSource.data = this.mapDataToTable(data.resource);
this.dataSource.paginator = this.paginator;
}
if (data && data.meta) {
this.tableLength = data.meta.count;
Expand All @@ -143,6 +149,7 @@ export abstract class DfManageTableComponent<T>

ngAfterViewInit(): void {
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
}

activeIcon(active: boolean): IconProp {
Expand Down Expand Up @@ -212,12 +219,14 @@ export abstract class DfManageTableComponent<T>
}

changePage(event: PageEvent): void {
if (event.previousPageIndex !== event.pageIndex) {
this.refreshTable(this.currentPageSize, event.pageIndex * event.pageSize);
} else {
this.currentPageSize = event.pageSize;
this.refreshTable(event.pageSize);
}
// if (event.previousPageIndex !== event.pageIndex) {
// console.log(event);
// this.refreshTable(undefined, event.pageIndex * event.pageSize);
// } else {
// console.log(event);
// this.currentPageSize = event.pageSize;
// this.refreshTable(event.pageSize);
// }
}

createRow(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/services/df-base-crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class DfBaseCrudService {
return this.http.get<T>(
this.url,
this.getOptions({
limit: 10,
limit: 100,
offset: 0,
includeCount: true,
...options,
Expand Down
31 changes: 28 additions & 3 deletions src/app/shared/utilities/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ export function mapSnakeToCamel<T>(obj: T): T {
}
}

// export const camelToSnakeString = (str: string) =>
// str.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1_$2').toLowerCase();

// export function mapCamelToSnake<T>(obj: T): T {
// if (Array.isArray(obj)) {
// return obj.map(item => mapCamelToSnake(item)) as unknown as T;
// } else if (typeof obj === 'object' && obj !== null) {
// const newObj: Record<string, unknown> = {};
// for (const key in obj) {
// if (Object.prototype.hasOwnProperty.call(obj, key)) {
// newObj[camelToSnakeString(key)] = mapCamelToSnake(
// (obj as Record<string, unknown>)[key]
// );
// }
// }
// return newObj as unknown as T;
// } else {
// return obj;
// }
// }

export const camelToSnakeString = (str: string) =>
str.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1_$2').toLowerCase();

Expand All @@ -29,9 +50,13 @@ export function mapCamelToSnake<T>(obj: T): T {
const newObj: Record<string, unknown> = {};
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
newObj[camelToSnakeString(key)] = mapCamelToSnake(
(obj as Record<string, unknown>)[key]
);
if (key === 'requestBody') {
newObj[key] = (obj as Record<string, unknown>)[key];
} else {
newObj[camelToSnakeString(key)] = mapCamelToSnake(
(obj as Record<string, unknown>)[key]
);
}
}
}
return newObj as unknown as T;
Expand Down