Skip to content

Commit

Permalink
DAT-873 documentation 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
asmajicbecon committed Jun 19, 2024
1 parent 12bfc6f commit 55c8079
Show file tree
Hide file tree
Showing 32 changed files with 1,205 additions and 841 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@
id="category-types"
dndDropzone
class="drop-zone"
data-content="Drop type here"
data-content="Drop types here"
(dndDrop)="onDrop($event, assignedTypes, true)"
>
<div class="drop-zone" dndPlaceholderRef data-content="Drop type here">
<div class="drop-zone" dndPlaceholderRef data-content="Drop types here">
</div>
<ng-container *ngFor="let type of assignedTypes">
<li
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ObjectLogChangeViewComponent {
if (value && !Array.isArray(value)) {
const before = value.old;
const after = value.new;
//DAT-774

if (isArray(before) && isArray(after)) {
value.old = before.sort((a, b) => (a.name > b.name) ? 1 : -1);
value.new = after.sort((a, b) => (a.name > b.name) ? 1 : -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
[totalItems]="tableMultiDataValues.length"
[searchEnabled]="false"
[pageSize]="pageSizeLimit"
[paginationEnabled]="showPagination()"
(pageChange)="onPageChange($event)"
/>
</fieldset>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,36 @@ export class MultiDataSectionComponent extends BaseSectionComponent implements O
return this.mode == CmdbMode.Create || this.mode == CmdbMode.Edit;
}


/**
* Only shows the pagination if there are more than 10 entries in the MDS table
* @returns Boolean if there are more than 10 entries in the MDS table
*/
showPagination(): boolean {
return this.tableMultiDataValues.length > 10;
}


calculateCurrentPage(action: string = ""): void {
if (action == "create") {
let maxPageSize = Math.ceil(this.tableMultiDataValues.length / 10);

if( this.currentPage < maxPageSize) {
this.currentPage = maxPageSize;
this.setValuesForPagination();
}
}

if (action == "delete") {
let maxPageSize = Math.floor(this.tableMultiDataValues.length / 10);

if (this.currentPage > maxPageSize) {
this.currentPage = maxPageSize;
this.setValuesForPagination();
}
}
}

/* ------------------------------------------------------------------------------------------------------------------ */
/* EVENT HANDLING */
/* ------------------------------------------------------------------------------------------------------------------ */
Expand All @@ -397,6 +427,7 @@ export class MultiDataSectionComponent extends BaseSectionComponent implements O
this.tableMultiDataValues.push(values);
this.setValuesForPagination();
this.incrementCurrentMultiDataID();
this.calculateCurrentPage("create");

this.form.markAsDirty();
}
Expand Down Expand Up @@ -446,6 +477,7 @@ export class MultiDataSectionComponent extends BaseSectionComponent implements O
this.modalRef.result.then((deleteConfirm: boolean) => {
if(deleteConfirm){
this.removeDataSet(rowIndex);
this.calculateCurrentPage("delete");
this.form.markAsDirty();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,49 +52,91 @@ export class DocapiBuilderComponent {
@ViewChild(DocapiBuilderStyleStepComponent, { static: true })
public styleStep: DocapiBuilderStyleStepComponent;

/* ------------------------------------------------------------------------------------------------------------------ */
/* LIFE CYCLE */
/* ------------------------------------------------------------------------------------------------------------------ */

constructor(private docapiService: DocapiService, private router: Router, private toast: ToastService) {
constructor(
private docapiService: DocapiService,
private router: Router,
private toast: ToastService
) {

}

/* ------------------------------------------------ HELPER FUNCTIONS ------------------------------------------------ */

public saveDoc() {
if (this.mode === CmdbMode.Create) {
/**
* Saves the document based on the current mode (Create or Edit).
* Initializes the document instance if in Create mode.
* Updates the document instance with form values.
* Handles the API call for creating or editing the document.
*/
public saveDoc(): void {
if (!this.docInstance && this.mode === CmdbMode.Create) {
this.docInstance = new DocTemplate();
}

this.docInstance.name = this.settingsStep.settingsForm.get('name').value;
this.docInstance.label = this.settingsStep.settingsForm.get('label').value;
this.docInstance.active = this.settingsStep.settingsForm.get('active').value;
this.docInstance.description = this.settingsStep.settingsForm.get('description').value;
this.docInstance.template_type = this.typeStep.typeForm.get('template_type').value;
this.docInstance.template_parameters = this.typeStep.typeParamComponent.typeParamForm.value;
this.docInstance.template_data = this.contentStep.contentForm.get('template_data').value;
this.docInstance.template_style = this.styleStep.styleForm.get('template_style').value;
this.updateDocInstance();

if (this.mode === CmdbMode.Create) {
let newId = null;

this.docapiService.postDocTemplate(this.docInstance).subscribe({
next: publicIdResp => {
newId = publicIdResp;
this.router.navigate(['/docapi/'], { queryParams: { docAddSuccess: newId } });
},
error: (error) => {
console.error(error);
}
});

this.handleCreateMode();
} else if (this.mode === CmdbMode.Edit) {
this.docapiService.putDocTemplate(this.docInstance).subscribe({
next: (updateResp: DocTemplate) => {
this.toast.success(`DocAPI document successfully edited: ${ updateResp.public_id }`);
this.router.navigate(['/docapi/'], { queryParams: { docEditSuccess: updateResp.public_id } });
},
error: (error) => {
console.error(error);
}
});
this.handleEditMode();
}
}


/**
* Updates the document instance properties with values from the form.
*/
private updateDocInstance(): void {
const { settingsForm } = this.settingsStep;
const { typeForm, typeParamComponent } = this.typeStep;
const { contentForm } = this.contentStep;
const { styleForm } = this.styleStep;

this.docInstance.name = settingsForm.get('name').value;
this.docInstance.label = settingsForm.get('label').value;
this.docInstance.active = settingsForm.get('active').value;
this.docInstance.description = settingsForm.get('description').value;
this.docInstance.template_type = typeForm.get('template_type').value;
this.docInstance.template_parameters = typeParamComponent.typeParamForm.value;
this.docInstance.template_data = contentForm.get('template_data').value;
this.docInstance.template_style = styleForm.get('template_style').value;
}


/**
* Handles the creation of a new document by making an API call.
* On success, navigates to the document list with a success query parameter.
*/
private handleCreateMode(): void {
this.docapiService.postDocTemplate(this.docInstance).subscribe({
next: (publicIdResp: string) => {
this.toast.success("DocAPI document successfully created!");
this.router.navigate(['/docapi/'], { queryParams: { docAddSuccess: publicIdResp } });
},
error: (error: any) => {
console.error(error);
}
});
}


/**
* Handles the editing of an existing document by making an API call.
* On success, shows a success toast and navigates to the document list with a success query parameter.
*/
private handleEditMode(): void {
this.docapiService.putDocTemplate(this.docInstance).subscribe({
next: (updateResp: DocTemplate) => {
this.toast.success(`DocAPI document successfully edited: ${updateResp.public_id}`);
this.router.navigate(['/docapi/'], { queryParams: { docEditSuccess: updateResp.public_id } });
},
error: (error: any) => {
console.error(error);
}
});
}
}
18 changes: 10 additions & 8 deletions cmdb/interface/api_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,25 @@ def __init__(self, projection: Union[dict, list] = None):


@staticmethod
def __validate_inclusion(projection: dict, match: int = 1) -> list:
def __validate_inclusion(projection: dict, match: int = 1) -> list[str]:
"""
Validation helper function the check the projection inclusion.
Validation helper function to check the projection inclusion
Args:
projection (dict): Projection parameters
match: matching value in dict or list.
match (int): Matching value in dict or list. Must be 0 or 1.
Returns:
List of all values with the matching parameters.
list[str]: List of all keys with the matching parameters
Raises:
ValueError: if value is not 0 or 1.
ValueError: If match is not 0 or 1
"""
if 0 <= match <= 1:
return [key for key, value in projection.items() if value == match]
if match not in [0, 1]:
raise ValueError('Projection parameter must be 0 or 1.')

return [key for key, value in projection.items() if value == match]

raise ValueError('Projection parameter must be 0 or 1.')


@property
Expand Down
Loading

0 comments on commit 55c8079

Please sign in to comment.