-
Notifications
You must be signed in to change notification settings - Fork 462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get categories childrens and add breadcrumb #23260
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f9d8be5
get categories childrens and add breadcrumb
zulqarnainvd 013e3a5
refactor: changes according to PR
zulqarnainvd ff9fcbe
refactor: add unit test case of category listing component
zulqarnainvd 26baa5c
dotCMS/core#23252 working on categories feedbacks and write test cases
zulqarnainvd 7b045c5
dotCMS/core#23252 working on categories feedbacks and write test cases
zulqarnainvd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
|
||
import { CoreWebService } from '@dotcms/dotcms-js'; | ||
|
||
import { DotHttpErrorManagerService } from '@services/dot-http-error-manager/dot-http-error-manager.service'; | ||
import { | ||
DotCategoriesService, | ||
CATEGORY_API_URL, | ||
CATEGORY_CHILDREN_API_URL | ||
} from './dot-categories.service'; | ||
import { CoreWebServiceMock } from '@tests/core-web.service.mock'; | ||
import { of } from 'rxjs'; | ||
import { CATEGORY_SOURCE, DotCategory } from '@models/categories/dot-categories.model'; | ||
|
||
const mockCategory: DotCategory = { | ||
categoryId: '1222', | ||
categoryName: 'Test', | ||
key: 'adsdsd', | ||
sortOrder: 1, | ||
deleted: false, | ||
categoryVelocityVarName: 'sdsdsds', | ||
friendlyName: 'asas', | ||
identifier: '1222', | ||
inode: '2121', | ||
name: 'Test', | ||
type: 'ggg', | ||
source: CATEGORY_SOURCE.DB | ||
}; | ||
|
||
describe('DotCategorysService', () => { | ||
let service: DotCategoriesService; | ||
let httpMock: HttpTestingController; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
DotCategoriesService, | ||
{ | ||
provide: DotHttpErrorManagerService, | ||
useValue: { | ||
handle() { | ||
return of({}); | ||
} | ||
} | ||
}, | ||
{ | ||
provide: CoreWebService, | ||
useClass: CoreWebServiceMock | ||
} | ||
], | ||
imports: [HttpClientTestingModule] | ||
}); | ||
service = TestBed.inject(DotCategoriesService); | ||
|
||
httpMock = TestBed.inject(HttpTestingController); | ||
}); | ||
|
||
it('should get a categories list', () => { | ||
service | ||
.getCategories({ | ||
first: 0, | ||
rows: 40, | ||
sortOrder: 1, | ||
filters: {}, | ||
globalFilter: null | ||
}) | ||
.subscribe((categories: DotCategory[]) => { | ||
expect(categories).toEqual([mockCategory]); | ||
}); | ||
|
||
const req = httpMock.expectOne(`${CATEGORY_API_URL}?direction=ASC&per_page=40`); | ||
|
||
expect(req.request.method).toBe('GET'); | ||
|
||
req.flush({ | ||
entity: [mockCategory] | ||
}); | ||
}); | ||
|
||
it('should get a children categories list', () => { | ||
service | ||
.getChildrenCategories({ | ||
first: 0, | ||
rows: 40, | ||
sortOrder: 1, | ||
filters: { | ||
inode: { value: '123' } | ||
}, | ||
globalFilter: null | ||
}) | ||
.subscribe((categories: DotCategory[]) => { | ||
expect(categories).toEqual([mockCategory]); | ||
}); | ||
|
||
const req = httpMock.expectOne( | ||
`${CATEGORY_CHILDREN_API_URL}?direction=ASC&per_page=40&inode=123` | ||
); | ||
|
||
expect(req.request.method).toBe('GET'); | ||
|
||
req.flush({ | ||
entity: [mockCategory] | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,25 +5,49 @@ import { LazyLoadEvent } from 'primeng/api'; | |
import { Observable } from 'rxjs'; | ||
import { OrderDirection, PaginatorService } from '../paginator'; | ||
|
||
export const CATEGORY_API_URL = 'v1/categories'; | ||
|
||
export const CATEGORY_CHILDREN_API_URL = 'v1/categories/children'; | ||
|
||
@Injectable() | ||
export class DotCategoriesService extends PaginatorService { | ||
constructor(coreWebService: CoreWebService) { | ||
super(coreWebService); | ||
this.url = 'v1/categories'; | ||
this.url = CATEGORY_API_URL; | ||
} | ||
|
||
updatePaginationService(event?: LazyLoadEvent) { | ||
const { sortField, sortOrder, filters } = event; | ||
this.setExtraParams('inode', filters?.inode?.value || null); | ||
this.filter = event?.filters?.global?.value || ''; | ||
this.sortField = sortField; | ||
this.sortOrder = sortOrder === 1 ? OrderDirection.ASC : OrderDirection.DESC; | ||
} | ||
|
||
/** | ||
* Get categories according to pagination and search | ||
* @param {LazyLoadEvent} [filters] | ||
* @param {LazyLoadEvent} [event] | ||
* @return {*} {Observable<DotCategory[]>} | ||
* @memberof DotCategoriesService | ||
*/ | ||
getCategories(filters?: LazyLoadEvent): Observable<DotCategory[]> { | ||
const { sortField, sortOrder } = filters; | ||
const page = parseInt(String(filters.first / this.paginationPerPage), 10) + 1; | ||
this.filter = filters?.filters?.global?.value || ''; | ||
this.sortField = sortField; | ||
this.sortOrder = sortOrder === 1 ? OrderDirection.ASC : OrderDirection.DESC; | ||
getCategories(event?: LazyLoadEvent): Observable<DotCategory[]> { | ||
this.url = CATEGORY_API_URL; | ||
this.updatePaginationService(event); | ||
const page = parseInt(String(event.first / this.paginationPerPage), 10) + 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the page do not come in the event to avoid this calculation ? |
||
|
||
return this.getPage(page); | ||
} | ||
|
||
/** | ||
* Get children categories according to pagination and search | ||
* @param {LazyLoadEvent} [event] | ||
* @return {*} {Observable<DotCategory[]>} | ||
* @memberof DotCategoriesService | ||
*/ | ||
getChildrenCategories(event?: LazyLoadEvent): Observable<DotCategory[]> { | ||
this.url = CATEGORY_CHILDREN_API_URL; | ||
this.updatePaginationService(event); | ||
const page = parseInt(String(event.first / this.paginationPerPage), 10) + 1; | ||
|
||
return this.getPage(page); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
<dot-portlet-base *ngIf="vm$ | async as vm"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to update the testing on this. |
||
<div class="px-3 py-2"> | ||
<p-breadcrumb | ||
[model]="vm.categoryBreadCrumbs" | ||
[home]="breadCrumbHome" | ||
(onItemClick)="updateBreadCrumb($event)" | ||
> | ||
</p-breadcrumb> | ||
</div> | ||
<div class="category_listing"> | ||
<p-table | ||
#dataTable | ||
|
@@ -8,13 +16,13 @@ | |
[rows]="vm.paginationPerPage" | ||
[totalRecords]="vm.totalRecords" | ||
[paginator]="true" | ||
[metaKeySelection]="true" | ||
[reorderableColumns]="true" | ||
[columns]="vm.tableColumns" | ||
(onLazyLoad)="loadCategories($event)" | ||
(onRowSelect)="handleRowCheck()" | ||
(onRowUnselect)="handleRowCheck()" | ||
(onHeaderCheckboxToggle)="handleRowCheck()" | ||
(onRowSelect)="handleRowCheck($event)" | ||
(onRowUnselect)="handleRowCheck($event)" | ||
(onHeaderCheckboxToggle)="handleRowCheck($event)" | ||
(onFilter)="handleFilter()" | ||
selectionMode="checkbox" | ||
loadingIcon="fa fa-circle-o-notch fa-spin" | ||
dataKey="categoryId" | ||
|
@@ -30,7 +38,7 @@ | |
type="button" | ||
pButton | ||
icon="pi pi-ellipsis-v" | ||
attr.data-testid="actions" | ||
attr.data-testId="actions" | ||
></button> | ||
<p-menu | ||
#actionsMenu | ||
|
@@ -40,31 +48,35 @@ | |
></p-menu> | ||
</div> | ||
<div class="w-2"> | ||
<div class="p-inputgroup searchBox"> | ||
<span class="p-inputgroup-addon"><i class="pi pi-search"></i></span> | ||
<div class="p-inputgroup"> | ||
<span class="border-right-none p-inputgroup-addon" | ||
><i class="pi pi-search"></i | ||
></span> | ||
<input | ||
class="border-left-none" | ||
#gf | ||
[placeholder]="'message.category.search' | dm" | ||
(input)="dataTable.filterGlobal($event.target.value, 'contains')" | ||
type="text" | ||
pInputText | ||
placeholder="Type to filter" | ||
/> | ||
</div> | ||
</div> | ||
<div> | ||
<button | ||
class="p-button-outlined" | ||
[label]="'message.category.import' | dm" | ||
pButton | ||
pRipple | ||
type="button" | ||
label="IMPORT" | ||
icon="pi pi-upload" | ||
></button> | ||
<button | ||
class="p-button-outlined mx-4" | ||
[label]="'message.category.export' | dm" | ||
pButton | ||
pRipple | ||
type="button" | ||
label="EXPORT" | ||
icon="pi pi-download" | ||
></button> | ||
<button | ||
|
@@ -78,14 +90,15 @@ | |
</div> | ||
</ng-template> | ||
<ng-template pTemplate="header" let-columns> | ||
<tr> | ||
<tr data-testId="testHeadTableRow"> | ||
<th class="tableHeader" style="width: 3rem"></th> | ||
<th class="tableHeader" style="width: 3rem"> | ||
<p-tableHeaderCheckbox></p-tableHeaderCheckbox> | ||
</th> | ||
<th | ||
class="tableHeader" | ||
*ngFor="let col of columns" | ||
[ngStyle]="{ width: col.width }" | ||
[pSortableColumn]="col.fieldName" | ||
> | ||
{{ col.header }} | ||
|
@@ -94,21 +107,31 @@ | |
</tr> | ||
</ng-template> | ||
<ng-template pTemplate="body" let-category let-index="rowIndex" let-columns="columns"> | ||
<tr [pReorderableRow]="index" [pSelectableRow]="category"> | ||
<tr | ||
[pReorderableRow]="index" | ||
[pSelectableRow]="category" | ||
(click)="addBreadCrumb(category)" | ||
data-testId="testTableRow" | ||
> | ||
<td> | ||
<span class="pi pi-bars" pReorderableRowHandle></span> | ||
</td> | ||
<td style="width: 3rem"> | ||
<td (click)="$event.stopPropagation()" style="width: 3rem"> | ||
<p-tableCheckbox [value]="category"></p-tableCheckbox> | ||
</td> | ||
<td *ngFor="let col of columns"> | ||
<td *ngFor="let col of columns" [ngStyle]="{ width: col.width }"> | ||
<ng-container *ngIf="col.fieldName === 'sortOrder'; else Actions"> | ||
<p-inplace #editText styleClass="listing__categories__sortOrder"> | ||
<p-inplace | ||
#editText | ||
(click)="$event.stopPropagation()" | ||
styleClass="category_listing__sortOrder" | ||
> | ||
<ng-template pTemplate="content"> | ||
<span class="p-input-icon-right"> | ||
<i class="pi pi-times" (click)="editText.deactivate()"></i> | ||
<p-inputNumber | ||
[ngModel]="category.sortOrder" | ||
inputStyleClass="category_listing__sortOrder__field" | ||
></p-inputNumber> | ||
</span> | ||
</ng-template> | ||
|
@@ -119,22 +142,46 @@ | |
</p-inplace> | ||
</ng-container> | ||
<ng-template #Actions> | ||
<ng-container *ngIf="col.fieldName === 'Actions'; else third"> | ||
<ng-container *ngIf="col.fieldName === 'Actions'; else last"> | ||
<dot-action-menu-button | ||
class="listing-categories__action-button" | ||
[attr.data-testid]="category.categoryId" | ||
[attr.data-testId]="category.categoryId" | ||
[actions]="vm.categoriesActions" | ||
[item]="category" | ||
> | ||
</dot-action-menu-button> | ||
</ng-container> | ||
</ng-template> | ||
<ng-template #third> | ||
<ng-template #last> | ||
{{ category[col.fieldName] }} | ||
</ng-template> | ||
</td> | ||
</tr> | ||
</ng-template> | ||
<ng-template pTemplate="emptymessage" let-columns> | ||
<tr> | ||
<td class="p-0" [attr.colspan]="columns.length + 3"> | ||
<div | ||
class="category_listing-datatable__empty" | ||
*ngIf="isContentFiltered; else emptyState" | ||
data-testId="category_listing-datatable__empty" | ||
> | ||
{{ 'No-Results-Found' | dm }} | ||
</div> | ||
<ng-template #emptyState> | ||
<dot-empty-state | ||
[rows]="10" | ||
[colsTextWidth]="[60, 50, 60, 80]" | ||
[title]="'message.category.empty.title' | dm" | ||
[content]="'message.category.empty.content' | dm" | ||
[buttonLabel]="'message.category.empty.button.label' | dm" | ||
icon="web" | ||
> | ||
</dot-empty-state> | ||
</ng-template> | ||
</td> | ||
</tr> | ||
</ng-template> | ||
</p-table> | ||
</div> | ||
</dot-portlet-base> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why event here is optional?