Skip to content

Commit

Permalink
Merge pull request exadel-inc#668 from exadel-inc/EFRS-1173-Subject-l…
Browse files Browse the repository at this point in the history
…oaded-files-counter-Examples-does-not-work-correctly

EFRS-1173   Displaying total number of examples
  • Loading branch information
smchedlidze826 committed Dec 3, 2021
2 parents 35c9e64 + a7bd3be commit 71eeb53
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion ui/src/app/core/collection/collection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export class CollectionService {
.pipe(
map((resp: { faces: SubjectExampleResponseItem[] }) => {
const totalPages = resp['total_pages'];
return resp.faces.map(el => ({ ...el, page: page, totalPages: totalPages }));
const totalElements = resp['total_elements'];
return resp.faces.map(el => ({ ...el, page: page, totalPages: totalPages, totalElements: totalElements }));
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
<ng-container *ngSwitchCase="subjectModeEnum.BulkSelect"
>{{ 'manage_collection.right_side.selected_examples' | translate }} {{ selectedIds.length }}</ng-container
>
<ng-container *ngSwitchDefault
>{{ 'manage_collection.right_side.examples' | translate }} {{ collectionItems.length }}</ng-container
>
<ng-container *ngSwitchDefault>{{ 'manage_collection.right_side.examples' | translate }} {{ totalElements }}</ng-container>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { CircleLoadingProgressEnum } from 'src/app/data/enums/circle-loading-progress.enum';
import { SubjectModeEnum } from 'src/app/data/enums/subject-mode.enum';
import { CollectionItem } from 'src/app/data/interfaces/collection';

Expand All @@ -22,10 +23,12 @@ import { CollectionItem } from 'src/app/data/interfaces/collection';
templateUrl: './collection-manager-subject-right.component.html',
styleUrls: ['./collection-manager-subject-right.component.scss'],
})
export class CollectionManagerSubjectRightComponent {
export class CollectionManagerSubjectRightComponent implements OnChanges {
scrollWindow: boolean = false;
prevItemCollection: CollectionItem[] = [];
subjectModeEnum = SubjectModeEnum;
uploadedExamples: CollectionItem[] = [];
totalElements: number = 0;

@Input() isPending: boolean;
@Input() isCollectionPending: boolean;
Expand All @@ -49,8 +52,24 @@ export class CollectionManagerSubjectRightComponent {
@Output() selectExample = new EventEmitter<CollectionItem>();
@Output() loadMore = new EventEmitter<CollectionItem>();

ngOnChanges(changes: SimpleChanges) {
const change = changes['collectionItems'];

if (change && change['currentValue'] !== change['previousValue']) {
const examples = this.collectionItems.filter(
item => item['totalElements'] === undefined && item.status === CircleLoadingProgressEnum.Uploaded
);

this.uploadedExamples = this.collectionItems.filter(item => item.status === CircleLoadingProgressEnum.Uploaded);

this.uploadedExamples.length && this.collectionItems[0]['totalElements']
? (this.totalElements = examples.length + this.collectionItems[0]['totalElements'])
: (this.totalElements = examples.length || 0);
}
}

onScrollDown(): void {
const lastItem = this.collectionItems[this.collectionItems.length - 1];
const lastItem = this.uploadedExamples[this.uploadedExamples.length - 1];
const nextPage = lastItem['page'] + 1;
const totalPages = lastItem['totalPages'];

Expand Down
2 changes: 2 additions & 0 deletions ui/src/app/store/manage-collectiom/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const reducer: ActionReducer<CollectionEntityState> = createReducer(
subject: item.subject,
page: item['page'],
totalPages: item['totalPages'],
totalElements: item['totalElements'],
}));

return {
Expand All @@ -150,6 +151,7 @@ const reducer: ActionReducer<CollectionEntityState> = createReducer(
subject: item.subject,
page: item['page'],
totalPages: item['totalPages'],
totalElements: item['totalElements'],
}));

return {
Expand Down

0 comments on commit 71eeb53

Please sign in to comment.