From c5386e5b7e32763b8029a6f7a6d985417fa17a2d Mon Sep 17 00:00:00 2001 From: Tadei-Mykola Date: Sat, 2 Nov 2024 20:32:18 +0200 Subject: [PATCH 1/3] rename in habit components --- .../add-comment/add-comment.component.spec.ts | 2 +- .../add-edit-custom-habit.component.html | 6 +- .../add-edit-custom-habit.component.scss | 8 +- .../add-edit-custom-habit.component.spec.ts | 8 +- .../add-edit-custom-habit.component.ts | 22 ++-- .../add-new-habit.component.html | 12 +- .../add-new-habit.component.scss | 8 +- .../add-new-habit.component.spec.ts | 48 ++++---- .../add-new-habit/add-new-habit.component.ts | 72 ++++++------ .../shopping-list.service.spec.ts | 88 -------------- .../shopping-list.service.ts | 46 -------- .../habit-edit-to-do-list.component.html} | 12 +- .../habit-edit-to-do-list.component.scss} | 8 +- .../habit-edit-to-do-list.component.spec.ts} | 60 +++++----- .../habit-edit-to-do-list.component.ts} | 70 +++++------ .../to-do-list.service.spec.ts | 88 ++++++++++++++ .../to-do-list.service.ts | 48 ++++++++ .../all-habits/all-habits.component.spec.ts | 2 +- .../user/components/habit/const/data.const.ts | 4 +- .../habit/mocks/habit-assigned-mock.ts | 10 +- .../user/components/habit/mocks/habit-mock.ts | 4 +- ...opping-list-mock.ts => to-do-list-mock.ts} | 30 ++--- .../interfaces/custom-habit.interface.ts | 6 +- .../interfaces/habit-assign.interface.ts | 4 +- .../models/interfaces/habit.interface.ts | 6 +- .../main/component/user/components/index.ts | 2 +- .../edit-profile/edit-profile-form-builder.ts | 4 +- .../edit-profile/edit-profile.component.html | 4 +- .../edit-profile.component.spec.ts | 6 +- .../edit-profile/edit-profile.component.ts | 6 +- .../profile-service/profile.service.spec.ts | 2 +- .../profile-header.component.spec.ts | 2 +- .../components/profile/profile.component.html | 4 +- .../components/profile/profile.component.scss | 14 +-- .../profile/profile.component.spec.ts | 2 +- .../shopping-list.component.html | 42 ------- .../shopping-list/shopping-list.component.ts | 109 ------------------ .../to-do-list/to-do-list.component.html | 40 +++++++ .../to-do-list.component.scss} | 14 +-- .../to-do-list.component.spec.ts} | 62 +++++----- .../to-do-list/to-do-list.component.ts | 109 ++++++++++++++++++ .../friend-profile-page.component.html | 2 +- .../friend-profile-page.component.scss | 2 +- .../user/models/edit-profile.model.ts | 4 +- .../user/models/shoppinglist.interface.ts | 25 ---- .../user/models/to-do-list.interface.ts | 25 ++++ src/app/main/component/user/user.module.ts | 10 +- .../goal/HabitAssignCustomPropertiesDto.ts | 6 +- .../habit-assign/habit-assign.service.spec.ts | 4 +- .../main/service/habit/habit.service.spec.ts | 14 +-- src/app/main/service/habit/habit.service.ts | 8 +- src/assets/mocks/events/mock-events.ts | 4 +- src/assets/mocks/habit/mock-habit-calendar.ts | 2 +- 53 files changed, 600 insertions(+), 600 deletions(-) delete mode 100644 src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/shopping-list.service.spec.ts delete mode 100644 src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/shopping-list.service.ts rename src/app/main/component/user/components/habit/add-new-habit/{habit-edit-shopping-list/habit-edit-shopping-list.component.html => habit-edit-to-do-list/habit-edit-to-do-list.component.html} (85%) rename src/app/main/component/user/components/habit/add-new-habit/{habit-edit-shopping-list/habit-edit-shopping-list.component.scss => habit-edit-to-do-list/habit-edit-to-do-list.component.scss} (97%) rename src/app/main/component/user/components/habit/add-new-habit/{habit-edit-shopping-list/habit-edit-shopping-list.component.spec.ts => habit-edit-to-do-list/habit-edit-to-do-list.component.spec.ts} (68%) rename src/app/main/component/user/components/habit/add-new-habit/{habit-edit-shopping-list/habit-edit-shopping-list.component.ts => habit-edit-to-do-list/habit-edit-to-do-list.component.ts} (73%) create mode 100644 src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/to-do-list.service.spec.ts create mode 100644 src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/to-do-list.service.ts rename src/app/main/component/user/components/habit/mocks/{shopping-list-mock.ts => to-do-list-mock.ts} (73%) delete mode 100644 src/app/main/component/user/components/profile/shopping-list/shopping-list.component.html delete mode 100644 src/app/main/component/user/components/profile/shopping-list/shopping-list.component.ts create mode 100644 src/app/main/component/user/components/profile/to-do-list/to-do-list.component.html rename src/app/main/component/user/components/profile/{shopping-list/shopping-list.component.scss => to-do-list/to-do-list.component.scss} (93%) rename src/app/main/component/user/components/profile/{shopping-list/shopping-list.component.spec.ts => to-do-list/to-do-list.component.spec.ts} (55%) create mode 100644 src/app/main/component/user/components/profile/to-do-list/to-do-list.component.ts delete mode 100644 src/app/main/component/user/models/shoppinglist.interface.ts create mode 100644 src/app/main/component/user/models/to-do-list.interface.ts diff --git a/src/app/main/component/comments/components/add-comment/add-comment.component.spec.ts b/src/app/main/component/comments/components/add-comment/add-comment.component.spec.ts index c547289f68..7c614bdac8 100644 --- a/src/app/main/component/comments/components/add-comment/add-comment.component.spec.ts +++ b/src/app/main/component/comments/components/add-comment/add-comment.component.spec.ts @@ -45,7 +45,7 @@ describe('AddCommentComponent', () => { rating: null, showEcoPlace: true, showLocation: true, - showShoppingList: true, + showToDoList: true, socialNetworks: [{ id: 1, url: defaultImagePath }] } as EditProfileModel; diff --git a/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.html b/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.html index 8e1ab2caf2..093a567b58 100644 --- a/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.html +++ b/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.html @@ -96,15 +96,15 @@

{{ 'user.habit.add-new-habit.textarea-title' | translate }}
-
+
-
- +
+
diff --git a/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.scss b/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.scss index fc4c8ac58d..005028cd38 100644 --- a/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.scss +++ b/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.scss @@ -80,14 +80,14 @@ } } - .duration-shoping { + .duration-to-do { display: flex; width: 100%; justify-content: space-between; gap: 32px; .duration, - .shopping { + .to-do { width: calc(50% - 16px); background: var(--secondary-light-grey); border-radius: 8px; @@ -352,13 +352,13 @@ input[type='radio'] + img { padding: 0; gap: 24px; - .duration-shoping { + .duration-to-do { flex-direction: column; height: auto; gap: 24px; .duration, - .shopping { + .to-do { width: 100%; } } diff --git a/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.spec.ts b/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.spec.ts index 3ca72e68a5..a087776252 100644 --- a/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.spec.ts +++ b/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.spec.ts @@ -13,11 +13,11 @@ import { HabitAssignService } from '@global-service/habit-assign/habit-assign.se import { HabitService } from '@global-service/habit/habit.service'; import { LocalStorageService } from '@global-service/localstorage/local-storage.service'; import { HabitDurationComponent } from '@global-user/components/habit/add-new-habit/habit-duration/habit-duration.component'; -import { HabitEditShoppingListComponent } from '@global-user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component'; +import { HabitEditToDoListComponent } from '@global-user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component'; import { HabitInviteFriendsComponent } from '@global-user/components/habit/add-new-habit/habit-invite-friends/habit-invite-friends.component'; import { HabitProgressComponent } from '@global-user/components/habit/add-new-habit/habit-progress/habit-progress.component'; import { CalendarWeekComponent } from '@global-user/components/profile/calendar/calendar-week/calendar-week.component'; -import { ShoppingList } from '@global-user/models/shoppinglist.interface'; +import { ToDoList } from '@global-user/models/to-do-list.interface'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { provideMockStore } from '@ngrx/store/testing'; import { TranslateModule } from '@ngx-translate/core'; @@ -82,7 +82,7 @@ describe('AddEditCustomHabitComponent', () => { HabitDurationComponent, CalendarWeekComponent, CalendarComponent, - HabitEditShoppingListComponent, + HabitEditToDoListComponent, HabitInviteFriendsComponent, HabitProgressComponent, SelectImagesComponent, @@ -152,7 +152,7 @@ describe('AddEditCustomHabitComponent', () => { }); it('should call changeCustomHabit() and goToAllHabits() on success', () => { - const habitFormValue = { title: 'Title', description: 'Description', complexity: 1, duration: 7, tagIds: [1], image: '', shopList: [] }; + const habitFormValue = { title: 'Title', description: 'Description', complexity: 1, duration: 7, tagIds: [1], image: '', toDoList: [] }; component.habitForm.setValue(habitFormValue); habitServiceMock.changeCustomHabit = jasmine.createSpy('changeCustomHabit').and.returnValue(of(null)); spyOn(component, 'goToAllHabits'); diff --git a/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.ts b/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.ts index 8f72ede29f..56e005e3e9 100644 --- a/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.ts +++ b/src/app/main/component/user/components/habit/add-edit-custom-habit/add-edit-custom-habit.component.ts @@ -14,7 +14,7 @@ import ImageResize from 'quill-image-resize-module'; import { HabitService } from '@global-service/habit/habit.service'; import { TagInterface } from '@shared/components/tag-filter/tag-filter.model'; import { quillConfig } from '../../../../events/components/event-editor/quillEditorFunc'; -import { ShoppingList } from '@global-user/models/shoppinglist.interface'; +import { ToDoList } from '@global-user/models/to-do-list.interface'; import { FileHandle } from '@eco-news-models/create-news-interface'; import { UserFriendsService } from '@global-user/services/user-friends.service'; import { TodoStatus } from '../models/todo-status.enum'; @@ -35,8 +35,8 @@ export class AddEditCustomHabitComponent extends FormBaseComponent implements On habitImages = HABIT_IMAGES; stars = STAR_IMAGES; initialDuration = HABIT_DEFAULT_DURATION; - shopList: ShoppingList[] = []; - newList: ShoppingList[] = []; + toDoList: ToDoList[] = []; + newList: ToDoList[] = []; tagsList: TagInterface[]; tagMaxLength = HABIT_TAGS_MAXLENGTH; selectedTagsList: number[]; @@ -151,13 +151,13 @@ export class AddEditCustomHabitComponent extends FormBaseComponent implements On return value <= complexity ? this.stars.GREEN : this.stars.WHITE; } - getShopList(list: ShoppingList[]): void { + getToDoList(list: ToDoList[]): void { this.newList = list.map((item) => ({ id: item.id, status: item.status, text: item.text })); - this.habitForm.get('shopList').setValue(this.newList); + this.habitForm.get('toDoList').setValue(this.newList); } getTagsList(list: TagInterface[]): void { @@ -217,7 +217,7 @@ export class AddEditCustomHabitComponent extends FormBaseComponent implements On duration: new FormControl(this.initialDuration, [Validators.required, Validators.min(7), Validators.max(56)]), tagIds: new FormControl([], Validators.required), image: new FormControl(''), - shopList: new FormControl([]) + toDoList: new FormControl([]) }); } @@ -230,13 +230,13 @@ export class AddEditCustomHabitComponent extends FormBaseComponent implements On duration: this.habit.defaultDuration, tagIds: this.habit.tags, image: this.habit.image, - shopList: this.habit.customShoppingListItems + toDoList: this.habit.customToDoListItems }); this.habitId = this.habit.id; - this.shopList = this.habit.customShoppingListItems?.length - ? [...(this.habit.customShoppingListItems || [])] - : [...(this.habit.customShoppingListItems || []), ...this.habit.shoppingListItems]; - this.shopList = this.shopList.map((el) => ({ ...el, selected: el.status === TodoStatus.inprogress })); + this.toDoList = this.habit.customToDoListItems?.length + ? [...(this.habit.customToDoListItems || [])] + : [...(this.habit.customToDoListItems || []), ...this.habit.ToDoListItems]; + this.toDoList = this.toDoList.map((el) => ({ ...el, selected: el.status === TodoStatus.inprogress })); } private subscribeToLangChange(): void { diff --git a/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.html b/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.html index 2bedd7542c..f0437cb8e0 100644 --- a/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.html +++ b/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.html @@ -46,7 +46,7 @@

{{ 'user.habit.info' | translate }}

>
-
+
{{ 'user.habit.info' | translate }}

-
- + + >
diff --git a/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.scss b/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.scss index e21e28345a..5e08e97963 100644 --- a/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.scss +++ b/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.scss @@ -196,14 +196,14 @@ } } - .duration-shoping { + .duration-to-do { display: flex; width: 100%; justify-content: space-between; gap: 32px; .duration, - .shopping { + .to-do { width: calc(50% - 16px); background: var(--secondary-light-grey); border-radius: 8px; @@ -402,13 +402,13 @@ padding: 0; gap: 24px; - .duration-shoping { + .duration-to-do { flex-direction: column; height: auto; gap: 24px; .duration, - .shopping { + .to-do { width: 100%; } } diff --git a/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.spec.ts b/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.spec.ts index 6ba397933e..599717e5ca 100644 --- a/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.spec.ts +++ b/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.spec.ts @@ -6,7 +6,7 @@ import { AddNewHabitComponent } from './add-new-habit.component'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { TranslateModule } from '@ngx-translate/core'; import { LocalStorageService } from '@global-service/localstorage/local-storage.service'; -import { ShoppingListService } from './habit-edit-shopping-list/shopping-list.service'; +import { ToDoListService } from './habit-edit-to-do-list/to-do-list.service'; import { HabitService } from '@global-service/habit/habit.service'; import { HabitAssignService } from '@global-service/habit-assign/habit-assign.service'; import { of, Subject } from 'rxjs'; @@ -80,14 +80,14 @@ describe('AddNewHabitComponent', () => { const matSnackBarMock: MatSnackBarComponent = jasmine.createSpyObj('MatSnackBarComponent', ['openSnackBar']); - const fakeShoppingListService: ShoppingListService = jasmine.createSpyObj('fakeShoppingListService', [ - 'getHabitAllShopLists', - 'getHabitShopList', - 'updateHabitShopList' + const fakeToDoListService: ToDoListService = jasmine.createSpyObj('fakeToDoListService', [ + 'getHabitAllToDoLists', + 'getHabitToDoList', + 'updateHabitToDoList' ]); - fakeShoppingListService.getHabitAllShopLists = () => of(); - fakeShoppingListService.getHabitShopList = () => of(); - fakeShoppingListService.updateHabitShopList = () => of(); + fakeToDoListService.getHabitAllToDoLists = () => of(); + fakeToDoListService.getHabitToDoList = () => of(); + fakeToDoListService.updateHabitToDoList = () => of(); matSnackBarMock.openSnackBar = (type: string) => type; @@ -115,7 +115,7 @@ describe('AddNewHabitComponent', () => { { provide: HabitService, useValue: fakeHabitService }, { provide: HabitAssignService, useValue: fakeHabitAssignService }, { provide: EcoNewsService, useValue: ecoNewsServiceMock }, - { provide: ShoppingListService, useValue: fakeShoppingListService }, + { provide: ToDoListService, useValue: fakeToDoListService }, { provide: LocalStorageService, useValue: fakeLocalStorageService }, { provide: ActivatedRoute, useValue: mockActivatedRoute }, { provide: Location, useValue: locationMock }, @@ -144,8 +144,8 @@ describe('AddNewHabitComponent', () => { it('should navigate back on onGoBack without call dialog', () => { component.initialDuration = 1; component.newDuration = 1; - component.standardShopList = null; - component.customShopList = null; + component.standardToDoList = null; + component.customToDoList = null; const spy = spyOn(locationMock, 'back'); component.onGoBack(); expect(spy).toHaveBeenCalled(); @@ -169,22 +169,22 @@ describe('AddNewHabitComponent', () => { expect(component.canAcquire).toBeTruthy(); }); - it('should set standardShopList', () => { - component.getList(DEFAULTFULLINFOHABIT.shoppingListItems); - expect(component.standardShopList).toEqual([{ id: 6, status: TodoStatus.active, text: 'TEST' }]); - expect(component.customShopList).toEqual([]); + it('should set standardToDoList', () => { + component.getList(DEFAULTFULLINFOHABIT.toDoListItems); + expect(component.standardToDoList).toEqual([{ id: 6, status: TodoStatus.active, text: 'TEST' }]); + expect(component.customToDoList).toEqual([]); }); - it('should set and customShopList', () => { - component.getList(CUSTOMFULLINFOHABIT.shoppingListItems); - expect(component.customShopList).toEqual([{ id: 6, status: TodoStatus.active, text: 'TEST', custom: true }]); - expect(component.standardShopList).toEqual([]); + it('should set and customToDoList', () => { + component.getList(CUSTOMFULLINFOHABIT.toDoListItems); + expect(component.customToDoList).toEqual([{ id: 6, status: TodoStatus.active, text: 'TEST', custom: true }]); + expect(component.standardToDoList).toEqual([]); }); - it('should set standardShopList and customShopList', () => { - const shoppingListItems = DEFAULTFULLINFOHABIT.shoppingListItems.concat(CUSTOMFULLINFOHABIT.shoppingListItems); - component.getList(shoppingListItems); - expect(component.customShopList).toEqual(shoppingListItems.filter((item) => item.custom)); - expect(component.standardShopList).toEqual(shoppingListItems.filter((item) => !item.custom)); + it('should set standardToDoList and customToDoList', () => { + const toDoListItems = DEFAULTFULLINFOHABIT.toDoListItems.concat(CUSTOMFULLINFOHABIT.toDoListItems); + component.getList(toDoListItems); + expect(component.customToDoList).toEqual(toDoListItems.filter((item) => item.custom)); + expect(component.standardToDoList).toEqual(toDoListItems.filter((item) => !item.custom)); }); }); diff --git a/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.ts b/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.ts index 73c597b027..9442a5cf1b 100644 --- a/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.ts +++ b/src/app/main/component/user/components/habit/add-new-habit/add-new-habit.component.ts @@ -7,7 +7,7 @@ import { HabitService } from '@global-service/habit/habit.service'; import { LocalStorageService } from '@global-service/localstorage/local-storage.service'; import { TranslateService } from '@ngx-translate/core'; import { Subject } from 'rxjs'; -import { ShoppingListService } from './habit-edit-shopping-list/shopping-list.service'; +import { ToDoListService } from './habit-edit-to-do-list/to-do-list.service'; import { MatDialog, MatDialogRef } from '@angular/material/dialog'; import { WarningPopUpComponent } from '@shared/components'; import { Location } from '@angular/common'; @@ -20,7 +20,7 @@ import { HabitAcquireConfirm, HabitCongratulation, HabitGiveUp, HabitLeavePage } import { WarningDialog } from '@global-user/models/warning-dialog.inteface'; import { HabitAssignInterface } from '../models/interfaces/habit-assign.interface'; import { HabitInterface, HabitListInterface } from '../models/interfaces/habit.interface'; -import { AllShoppingLists, HabitUpdateShopList, ShoppingList } from '@user-models/shoppinglist.interface'; +import { AllToDoLists, HabitUpdateToDoList, ToDoList } from '@global-user/models/to-do-list.interface'; import { UserFriendsService } from '@global-user/services/user-friends.service'; import { HabitAssignCustomPropertiesDto, HabitAssignPropertiesDto } from '@global-models/goal/HabitAssignCustomPropertiesDto'; import { singleNewsImages } from 'src/app/main/image-pathes/single-news-images'; @@ -37,9 +37,9 @@ export class AddNewHabitComponent implements OnInit, OnDestroy { habitResponse: HabitInterface; recommendedHabits: HabitInterface[]; recommendedNews: EcoNewsModel[]; - initialShoppingList: ShoppingList[] = []; - standardShopList: ShoppingList[] = []; - customShopList: ShoppingList[] = []; + initialToDoList: ToDoList[] = []; + standardToDoList: ToDoList[] = []; + customToDoList: ToDoList[] = []; friendsIdsList: number[] = []; newDuration = 7; initialDuration: number; @@ -73,7 +73,7 @@ export class AddNewHabitComponent implements OnInit, OnDestroy { private snackBar: MatSnackBarComponent, private habitAssignService: HabitAssignService, private newsService: EcoNewsService, - private shopListService: ShoppingListService, + private toDoListService: ToDoListService, private localStorageService: LocalStorageService, private translate: TranslateService, private location: Location, @@ -124,7 +124,7 @@ export class AddNewHabitComponent implements OnInit, OnDestroy { this.isAcquired = this.assignedHabit.status === HabitStatus.ACQUIRED; this.initialDuration = res.duration || res.habit.defaultDuration; this.initHabitData(res.habit, res.duration || res.habit.defaultDuration); - this.getCustomShopList(); + this.getCustomToDoList(); }); } else { this.getDefaultHabit(); @@ -169,10 +169,10 @@ export class AddNewHabitComponent implements OnInit, OnDestroy { this.initHabitData(data); this.isCustomHabit = data.isCustomHabit; if (data.isCustomHabit) { - data.customShoppingListItems?.forEach((item) => (item.custom = true)); - this.initialShoppingList = data.customShoppingListItems; + data.customToDoListItems?.forEach((item) => (item.custom = true)); + this.initialToDoList = data.customToDoListItems; } else { - this.getStandardShopList(); + this.getStandardToDoList(); } }); } @@ -196,7 +196,7 @@ export class AddNewHabitComponent implements OnInit, OnDestroy { } onGoBack(): void { - const isHabitWasEdited = this.initialDuration !== this.newDuration || this.standardShopList || this.customShopList; + const isHabitWasEdited = this.initialDuration !== this.newDuration || this.standardToDoList || this.customToDoList; if (isHabitWasEdited) { const dialogRef = this.getOpenDialog(HabitLeavePage, false); if (!dialogRef) { @@ -230,28 +230,28 @@ export class AddNewHabitComponent implements OnInit, OnDestroy { } } - getList(list: ShoppingList[]): void { - this.standardShopList = list.filter((item) => !item.custom); - this.customShopList = list.filter((item) => item.custom); + getList(list: ToDoList[]): void { + this.standardToDoList = list.filter((item) => !item.custom); + this.customToDoList = list.filter((item) => item.custom); } - private getStandardShopList(): void { - this.shopListService - .getHabitShopList(this.habitId) + private getStandardToDoList(): void { + this.toDoListService + .getHabitToDoList(this.habitId) .pipe(take(1)) .subscribe((res) => { - this.initialShoppingList = res; + this.initialToDoList = res; }); } - private getCustomShopList(): void { - this.shopListService - .getHabitAllShopLists(this.habitAssignId, this.currentLang) + private getCustomToDoList(): void { + this.toDoListService + .getHabitAllToDoLists(this.habitAssignId, this.currentLang) .pipe(take(1)) - .subscribe((res: AllShoppingLists) => { - res.customShoppingListItemDto?.forEach((item) => (item.custom = true)); - this.initialShoppingList = [...res.customShoppingListItemDto, ...res.userShoppingListItemDto]; - this.getList(this.initialShoppingList); + .subscribe((res: AllToDoLists) => { + res.customToDoListItemDto?.forEach((item) => (item.custom = true)); + this.initialToDoList = [...res.customToDoListItemDto, ...res.userToDoListItemDto]; + this.getList(this.initialToDoList); }); } @@ -289,14 +289,14 @@ export class AddNewHabitComponent implements OnInit, OnDestroy { assignCustomHabit(): void { this.friendsIdsList = this.userFriendsService.addedFriends?.map((friend) => friend.id); const habitAssignPropertiesDto: HabitAssignPropertiesDto = { - defaultShoppingListItems: this.standardShopList.filter((item) => item.selected === true).map((item) => item.id), + defaultToDoListItems: this.standardToDoList.filter((item) => item.selected === true).map((item) => item.id), duration: this.newDuration, isPrivate: this.isPrivate }; const body: HabitAssignCustomPropertiesDto = { friendsIdsList: this.friendsIdsList, habitAssignPropertiesDto, - customShoppingListItemList: this.customShopList.map((item) => ({ text: item.text })) + customToDoListItemList: this.customToDoList.map((item) => ({ text: item.text })) }; this.habitAssignService @@ -312,9 +312,9 @@ export class AddNewHabitComponent implements OnInit, OnDestroy { .updateHabitDuration(this.habitAssignId, this.newDuration) .pipe(take(1)) .subscribe(() => { - if (this.customShopList || this.standardShopList) { - this.convertShopLists(); - this.shopListService.updateHabitShopList(this.setHabitListForUpdate()); + if (this.customToDoList || this.standardToDoList) { + this.convertToDoLists(); + this.toDoListService.updateHabitToDoList(this.setHabitListForUpdate()); } this.afterHabitWasChanged('habitUpdated'); }); @@ -334,12 +334,12 @@ export class AddNewHabitComponent implements OnInit, OnDestroy { }); } - private convertShopLists(): void { - this.customShopList?.forEach((el) => { + private convertToDoLists(): void { + this.customToDoList?.forEach((el) => { delete el.custom; delete el.selected; }); - this.standardShopList?.forEach((el) => { + this.standardToDoList?.forEach((el) => { delete el.custom; delete el.selected; }); @@ -350,11 +350,11 @@ export class AddNewHabitComponent implements OnInit, OnDestroy { this.snackBar.openSnackBar(kindOfChanges); } - private setHabitListForUpdate(): HabitUpdateShopList { + private setHabitListForUpdate(): HabitUpdateToDoList { return { habitAssignId: this.habitAssignId, - customShopList: this.customShopList, - standardShopList: this.standardShopList, + customToDoList: this.customToDoList, + standardToDoList: this.standardToDoList, lang: this.currentLang }; } diff --git a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/shopping-list.service.spec.ts b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/shopping-list.service.spec.ts deleted file mode 100644 index 4f073b5e63..0000000000 --- a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/shopping-list.service.spec.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { TestBed } from '@angular/core/testing'; -import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; - -import { ShoppingListService } from './shopping-list.service'; -import { TranslateModule, TranslateService } from '@ngx-translate/core'; -import { environment } from '@environment/environment'; -import { - ALLUSERSHOPLISTS, - CUSTOMSHOPITEM, - SHOPLIST, - SHOPLISTITEMONE, - SHOPLISTITEMTWO, - UPDATEHABITSHOPLIST -} from '../../mocks/shopping-list-mock'; - -describe('ShoppingListService', () => { - let service: ShoppingListService; - let httpMock: HttpTestingController; - - const mainLink = environment.backendLink; - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [HttpClientTestingModule, TranslateModule.forRoot()], - providers: [ShoppingListService, TranslateService] - }); - - service = TestBed.inject(ShoppingListService); - httpMock = TestBed.inject(HttpTestingController); - }); - - afterEach(() => { - httpMock.verify(); - }); - - it('should be created', () => { - expect(service).toBeTruthy(); - }); - - it('should return allShopList by habitId on getHabitAllShopLists', () => { - service.getHabitAllShopLists(2, 'en').subscribe((data) => { - expect(data).toEqual(ALLUSERSHOPLISTS); - }); - - const req = httpMock.expectOne(`${mainLink}habit/assign/2/allUserAndCustomList?lang=en`); - expect(req.request.responseType).toEqual('json'); - expect(req.request.method).toBe('GET'); - req.flush(ALLUSERSHOPLISTS); - }); - - it('should return all user shopList by lang on getUserShoppingLists', () => { - service.getUserShoppingLists('ua').subscribe((data) => { - expect(data).toEqual([ALLUSERSHOPLISTS]); - }); - - const req = httpMock.expectOne(`${mainLink}habit/assign/allUserAndCustomShoppingListsInprogress?lang=ua`); - expect(req.request.responseType).toEqual('json'); - expect(req.request.method).toBe('GET'); - req.flush([ALLUSERSHOPLISTS]); - }); - - it('should update Standard Shop Item Status', () => { - service.updateStandardShopItemStatus(SHOPLISTITEMTWO, 'ua').subscribe((data) => { - expect(data).toEqual([SHOPLISTITEMTWO]); - }); - const req = httpMock.expectOne(`${mainLink}user/shopping-list-items/2/status/INPROGRESS?lang=ua`); - expect(req.request.method).toBe('PATCH'); - req.flush([SHOPLISTITEMTWO]); - }); - - it('should update Custom Shop Item Status', () => { - service.updateCustomShopItemStatus(1, SHOPLISTITEMTWO).subscribe((data) => { - expect(data).toEqual(SHOPLISTITEMTWO); - }); - const req = httpMock.expectOne(`${mainLink}custom/shopping-list-items/1/custom-shopping-list-items?itemId=2&status=INPROGRESS`); - expect(req.request.method).toBe('PATCH'); - req.flush(SHOPLISTITEMTWO); - }); - - it('should update Habit Shop List', () => { - service.updateHabitShopList(UPDATEHABITSHOPLIST).subscribe((data) => { - expect(data).toEqual(null); - }); - const req = httpMock.expectOne(`${mainLink}habit/assign/2/allUserAndCustomList?lang=ua`); - expect(req.request.method).toBe('PUT'); - req.flush(null); - }); -}); diff --git a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/shopping-list.service.ts b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/shopping-list.service.ts deleted file mode 100644 index a4358e8809..0000000000 --- a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/shopping-list.service.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; -import { HttpClient } from '@angular/common/http'; -import { mainLink } from '../../../../../../links'; -import { AllShoppingLists, HabitUpdateShopList, ShoppingList } from '@user-models/shoppinglist.interface'; - -@Injectable({ - providedIn: 'root' -}) -export class ShoppingListService { - constructor(private http: HttpClient) {} - - getHabitShopList(habitId: number): Observable { - return this.http.get(`${mainLink}habit/${habitId}/shopping-list`); - } - - getHabitAllShopLists(habitAssignId: number, lang: string): Observable { - return this.http.get(`${mainLink}habit/assign/${habitAssignId}/allUserAndCustomList?lang=${lang}`); - } - - getUserShoppingLists(lang: string): Observable { - return this.http.get(`${mainLink}habit/assign/allUserAndCustomShoppingListsInprogress?lang=${lang}`); - } - - updateStandardShopItemStatus(item: ShoppingList, lang: string): Observable { - const body = {}; - return this.http.patch(`${mainLink}user/shopping-list-items/${item.id}/status/${item.status}?lang=${lang}`, body); - } - - updateCustomShopItemStatus(userId: number, item: ShoppingList): Observable { - const body = {}; - return this.http.patch( - `${mainLink}custom/shopping-list-items/${userId}/custom-shopping-list-items?itemId=${item.id}&status=${item.status}`, - body - ); - } - - updateHabitShopList(habitShopList: HabitUpdateShopList) { - const assignId = habitShopList.habitAssignId; - const body = { - customShoppingListItemDto: habitShopList.customShopList, - userShoppingListItemDto: habitShopList.standardShopList - }; - return this.http.put(`${mainLink}habit/assign/${assignId}/allUserAndCustomList?lang=${habitShopList.lang}`, body); - } -} diff --git a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component.html b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.html similarity index 85% rename from src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component.html rename to src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.html index cd39734542..62ae3bef0b 100644 --- a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component.html +++ b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.html @@ -1,10 +1,10 @@ -
+
{{ 'user.habit.to-do.to-do-list' | translate }}
-
-
    -
  • +
    +
      +
    -
    - {{ 'user.habit.to-do.no-shopping-items' | translate }} +
    + {{ 'user.habit.to-do.no-to-do-items' | translate }}
    diff --git a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component.scss b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.scss similarity index 97% rename from src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component.scss rename to src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.scss index dcc5be3e71..988d0769e3 100644 --- a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component.scss +++ b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.scss @@ -1,4 +1,4 @@ -.shop-list-container { +.to-do-list-container { position: relative; display: flex; flex-direction: column; @@ -40,7 +40,7 @@ flex-direction: column; height: 100%; - .shop-list { + .to-do-list { display: flex; flex-direction: column; height: 190px; @@ -83,7 +83,7 @@ } } - .shop-list-edit-mode { + .to-do-list-edit-mode { height: 112px; } @@ -183,7 +183,7 @@ form { } @media (max-width: 560px) { - .shop-list-container .title { + .to-do-list-container .title { font-size: 16px; margin-bottom: 20px; } diff --git a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component.spec.ts b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.spec.ts similarity index 68% rename from src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component.spec.ts rename to src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.spec.ts index 5b958838b0..161a9a45b7 100644 --- a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component.spec.ts +++ b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.spec.ts @@ -2,27 +2,27 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { ActivatedRoute } from '@angular/router'; import { HabitService } from '@global-service/habit/habit.service'; -import { ShoppingList } from '@global-user/models/shoppinglist.interface'; +import { ToDoList } from '@global-user/models/to-do-list.interface'; import { TranslateModule } from '@ngx-translate/core'; import { of } from 'rxjs'; import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; import { TodoStatus } from '../../models/todo-status.enum'; -import { HabitEditShoppingListComponent } from './habit-edit-shopping-list.component'; -import { ShoppingListService } from './shopping-list.service'; +import { HabitEditToDoListComponent } from './habit-edit-to-do-list.component'; +import { ToDoListService } from './to-do-list.service'; import { FormControl, FormGroup } from '@angular/forms'; import { MatDialog } from '@angular/material/dialog'; import { SimpleChange, SimpleChanges } from '@angular/core'; -describe('HabitEditShoppingListComponent', () => { - let component: HabitEditShoppingListComponent; - let fixture: ComponentFixture; +describe('HabitEditToDoListComponent', () => { + let component: HabitEditToDoListComponent; + let fixture: ComponentFixture; let snackBar: MatSnackBar; const mockActivatedRoute = { params: of({ habitId: 2 }) }; - const mockList: ShoppingList[] = [ + const mockList: ToDoList[] = [ { id: 1, status: TodoStatus.active, @@ -36,7 +36,7 @@ describe('HabitEditShoppingListComponent', () => { selected: false } ]; - const mockItem: ShoppingList = { + const mockItem: ToDoList = { id: 234, status: TodoStatus.active, text: 'Item 2', @@ -51,10 +51,10 @@ describe('HabitEditShoppingListComponent', () => { const matDialogRefMock = jasmine.createSpyObj(['open', 'afterClosed']); matDialogRefMock.open.and.returnValue({ afterClosed: () => of(true) }); TestBed.configureTestingModule({ - declarations: [HabitEditShoppingListComponent], + declarations: [HabitEditToDoListComponent], imports: [HttpClientTestingModule, TranslateModule.forRoot(), MatSnackBarModule], providers: [ - ShoppingListService, + ToDoListService, HabitService, MatSnackBar, { provide: ActivatedRoute, useValue: mockActivatedRoute }, @@ -64,18 +64,18 @@ describe('HabitEditShoppingListComponent', () => { })); beforeEach(() => { - fixture = TestBed.createComponent(HabitEditShoppingListComponent); + fixture = TestBed.createComponent(HabitEditToDoListComponent); component = fixture.componentInstance; snackBar = TestBed.inject(MatSnackBar); fixture.detectChanges(); - component.shopList = []; + component.toDoList = []; }); it('should create', () => { expect(component).toBeTruthy(); }); - it('should add item to shop list on additem', () => { + it('should add item to toDo list on additem', () => { const newList = [ { id: null, @@ -85,9 +85,9 @@ describe('HabitEditShoppingListComponent', () => { selected: true } ]; - component.shopList = []; + component.toDoList = []; component.addItem('test'); - expect(component.shopList).toEqual(newList); + expect(component.toDoList).toEqual(newList); }); it('should setValue empty string on add item', () => { @@ -98,49 +98,49 @@ describe('HabitEditShoppingListComponent', () => { it('should return disableCheck if isAcquired is true', () => { component.isAcquired = true; - const result = component.getCheckIcon({} as ShoppingList); + const result = component.getCheckIcon({} as ToDoList); expect(result).toBe(component.img.disableCheck); }); it('should return doneCheck if item status is done', () => { - const item: ShoppingList = { status: TodoStatus.done, text: mockText1, id: null }; + const item: ToDoList = { status: TodoStatus.done, text: mockText1, id: null }; const result = component.getCheckIcon(item); expect(result).toBe(component.img.doneCheck); }); it('should return minusCheck if item is selected', () => { - const item: ShoppingList = { selected: true, status: TodoStatus.inprogress, text: mockText2, id: null }; + const item: ToDoList = { selected: true, status: TodoStatus.inprogress, text: mockText2, id: null }; const result = component.getCheckIcon(item); expect(result).toBe(component.img.minusCheck); }); it('should return plusCheck if item is not selected and status is not done', () => { - const item: ShoppingList = { selected: false, status: TodoStatus.inprogress, text: mockText3, id: null }; + const item: ToDoList = { selected: false, status: TodoStatus.inprogress, text: mockText3, id: null }; const result = component.getCheckIcon(item); expect(result).toBe(component.img.plusCheck); }); it('should select item and change status to in progress if selected', () => { - const item: ShoppingList = mockList[0]; - component.shopList = [item]; + const item: ToDoList = mockList[0]; + component.toDoList = [item]; component.selectItem(item); - expect(component.shopList[0].selected).toBe(true); - expect(component.shopList[0].status).toBe(TodoStatus.inprogress); + expect(component.toDoList[0].selected).toBe(true); + expect(component.toDoList[0].status).toBe(TodoStatus.inprogress); }); it('should deselect item and change status to active if not selected', () => { - const item: ShoppingList = { id: null, status: TodoStatus.inprogress, text: 'item1', selected: true }; - component.shopList = [item]; + const item: ToDoList = { id: null, status: TodoStatus.inprogress, text: 'item1', selected: true }; + component.toDoList = [item]; component.selectItem(item); - expect(component.shopList[0].selected).toBe(false); - expect(component.shopList[0].status).toBe(TodoStatus.active); + expect(component.toDoList[0].selected).toBe(false); + expect(component.toDoList[0].status).toBe(TodoStatus.active); }); it('should move selected item to the top of the list', () => { - component.shopList = [...mockList]; + component.toDoList = [...mockList]; component.selectItem(mockList[1]); - expect(component.shopList[0]).toBe(mockList[1]); - expect(component.shopList[1]).toBe(mockList[0]); + expect(component.toDoList[0]).toBe(mockList[1]); + expect(component.toDoList[1]).toBe(mockList[0]); }); it('should not open snackbar if form is valid', () => { diff --git a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component.ts b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.ts similarity index 73% rename from src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component.ts rename to src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.ts index 598816d45e..7e4b973218 100644 --- a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component.ts +++ b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.ts @@ -3,22 +3,22 @@ import { Subject, Subscription } from 'rxjs'; import { AbstractControl, FormControl, FormGroup, Validators } from '@angular/forms'; import { LocalStorageService } from '@global-service/localstorage/local-storage.service'; import { TranslateService } from '@ngx-translate/core'; -import { ShoppingList } from '../../../../models/shoppinglist.interface'; +import { ToDoList } from '../../../../models/to-do-list.interface'; import { TodoStatus } from '../../models/todo-status.enum'; import { MatSnackBarComponent } from '@global-errors/mat-snack-bar/mat-snack-bar.component'; -import { FIELD_SYMBOLS_LIMIT, HABIT_SHOPPING_LIST_CHECK, SHOPPING_ITEM_NAME_LIMIT } from '../../const/data.const'; +import { FIELD_SYMBOLS_LIMIT, HABIT_TO_DO_LIST_CHECK, TO_DO_ITEM_NAME_LIMIT } from '../../const/data.const'; import { MatDialog } from '@angular/material/dialog'; import { WarningPopUpComponent } from '@shared/components'; import { take } from 'rxjs/operators'; @Component({ - selector: 'app-habit-edit-shopping-list', - templateUrl: './habit-edit-shopping-list.component.html', - styleUrls: ['./habit-edit-shopping-list.component.scss'], + selector: 'app-habit-edit-to-do-list', + templateUrl: './habit-edit-to-do-list.component.html', + styleUrls: ['./habit-edit-to-do-list.component.scss'], providers: [MatSnackBarComponent] }) -export class HabitEditShoppingListComponent implements OnInit, OnChanges, OnDestroy { - @Input() shopList: ShoppingList[] = []; +export class HabitEditToDoListComponent implements OnInit, OnChanges, OnDestroy { + @Input() toDoList: ToDoList[] = []; @Input() isAcquired = false; private fieldSymbolsLimit = FIELD_SYMBOLS_LIMIT; @@ -29,10 +29,10 @@ export class HabitEditShoppingListComponent implements OnInit, OnChanges, OnDest userId: number; private destroySub: Subject = new Subject(); private langChangeSub: Subscription; - shoppingItemNameLimit = SHOPPING_ITEM_NAME_LIMIT; + toDoItemNameLimit = TO_DO_ITEM_NAME_LIMIT; todoStatus = TodoStatus; isEditMode = false; - private shopListBeforeEditing: ShoppingList[] = []; + private toDoListBeforeEditing: ToDoList[] = []; isListChanged: boolean; private confirmDialogConfig = { hasBackdrop: true, @@ -48,9 +48,9 @@ export class HabitEditShoppingListComponent implements OnInit, OnChanges, OnDest private deleteItemTitle = `user.habit.to-do.item-delete-pop-up-title`; private cancelEditingTitle = `user.habit.to-do.cancel-pop-up-title`; - img = HABIT_SHOPPING_LIST_CHECK; + img = HABIT_TO_DO_LIST_CHECK; - @Output() newList = new EventEmitter(); + @Output() newList = new EventEmitter(); constructor( private snackBar: MatSnackBarComponent, @@ -62,12 +62,12 @@ export class HabitEditShoppingListComponent implements OnInit, OnChanges, OnDest ngOnInit() { this.subscribeToLangChange(); this.userId = this.localStorageService.getUserId(); - this.newList.emit(this.shopList); + this.newList.emit(this.toDoList); } ngOnChanges(changes: SimpleChanges): void { - if (changes.shopList) { - this.shopList.forEach((el) => (el.selected = el.status === TodoStatus.inprogress || el.status === TodoStatus.done)); + if (changes.toDoList) { + this.toDoList.forEach((el) => (el.selected = el.status === TodoStatus.inprogress || el.status === TodoStatus.done)); this.placeItemInOrder(); } } @@ -86,7 +86,7 @@ export class HabitEditShoppingListComponent implements OnInit, OnChanges, OnDest }); } - getCheckIcon(item: ShoppingList): string { + getCheckIcon(item: ToDoList): string { if (this.isAcquired) { return this.img.disableCheck; } @@ -106,16 +106,16 @@ export class HabitEditShoppingListComponent implements OnInit, OnChanges, OnDest selected: true }; if (newItem.text) { - this.shopList = [newItem, ...this.shopList]; + this.toDoList = [newItem, ...this.toDoList]; } this.item.setValue(''); this.placeItemInOrder(); - this.newList.emit(this.shopList); + this.newList.emit(this.toDoList); } - selectItem(item: ShoppingList): void { + selectItem(item: ToDoList): void { this.isListChanged = true; - this.shopList.map((element) => { + this.toDoList.map((element) => { if (element.text === item.text) { element.selected = !item.selected; element.status = item.selected ? TodoStatus.inprogress : TodoStatus.active; @@ -123,17 +123,17 @@ export class HabitEditShoppingListComponent implements OnInit, OnChanges, OnDest return element; }); if (item.selected) { - const index = this.shopList.indexOf(item); - this.shopList.splice(index, 1); - this.shopList = [item, ...this.shopList]; + const index = this.toDoList.indexOf(item); + this.toDoList.splice(index, 1); + this.toDoList = [item, ...this.toDoList]; } this.placeItemInOrder(); - this.newList.emit(this.shopList); + this.newList.emit(this.toDoList); } private placeItemInOrder(): void { const statusOrder = { DONE: 1, INPROGRESS: 2, ACTIVE: 3 }; - this.shopList.sort((a, b) => { + this.toDoList.sort((a, b) => { const statusDifference = statusOrder[a.status] - statusOrder[b.status]; const orderCustom = a.custom && !b.custom ? -1 : 1; return statusDifference || orderCustom; @@ -149,8 +149,8 @@ export class HabitEditShoppingListComponent implements OnInit, OnChanges, OnDest .pipe(take(1)) .subscribe((confirm) => { if (confirm) { - this.shopList = this.shopList.filter((elem) => elem.text !== text); - this.newList.emit(this.shopList); + this.toDoList = this.toDoList.filter((elem) => elem.text !== text); + this.newList.emit(this.toDoList); } }); } @@ -164,18 +164,18 @@ export class HabitEditShoppingListComponent implements OnInit, OnChanges, OnDest changeEditMode(): void { if (!this.isEditMode) { this.isListChanged = false; - this.shopListBeforeEditing = []; - this.shopList.forEach((el) => this.shopListBeforeEditing.push({ ...el })); + this.toDoListBeforeEditing = []; + this.toDoList.forEach((el) => this.toDoListBeforeEditing.push({ ...el })); } this.isEditMode = !this.isEditMode; } private isListItemsChanged(): boolean { - const isItemsChanged = !this.shopList.every((el) => { - const itemBeforeEditing = this.shopListBeforeEditing.find((item) => item.id === el.id); + const isItemsChanged = !this.toDoList.every((el) => { + const itemBeforeEditing = this.toDoListBeforeEditing.find((item) => item.id === el.id); return itemBeforeEditing && Object.keys(el).every((key) => el[key] === itemBeforeEditing[key]); }); - const isLengthChanged = this.shopList.length !== this.shopListBeforeEditing.length; + const isLengthChanged = this.toDoList.length !== this.toDoListBeforeEditing.length; return isItemsChanged || isLengthChanged; } @@ -188,11 +188,11 @@ export class HabitEditShoppingListComponent implements OnInit, OnChanges, OnDest .pipe(take(1)) .subscribe((confirm) => { if (confirm) { - this.shopList = []; - this.shopListBeforeEditing.forEach((el) => { - this.shopList.push(el); + this.toDoList = []; + this.toDoListBeforeEditing.forEach((el) => { + this.toDoList.push(el); }); - this.newList.emit(this.shopList); + this.newList.emit(this.toDoList); this.isEditMode = false; } }); diff --git a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/to-do-list.service.spec.ts b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/to-do-list.service.spec.ts new file mode 100644 index 0000000000..7bccc38b57 --- /dev/null +++ b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/to-do-list.service.spec.ts @@ -0,0 +1,88 @@ +import { TestBed } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; + +import { ToDoListService } from './to-do-list.service'; +import { TranslateModule, TranslateService } from '@ngx-translate/core'; +import { environment } from '@environment/environment'; +import { + ALLUSERTODOLISTS, + CUSTOMTODOITEM, + TODOLIST, + TODOLISTITEMONE, + TODOLISTITEMTWO, + UPDATEHABITTODOLIST +} from '../../mocks/to-do-list-mock'; + +describe('ToDoListService', () => { + let service: ToDoListService; + let httpMock: HttpTestingController; + + const mainLink = environment.backendLink; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule, TranslateModule.forRoot()], + providers: [ToDoListService, TranslateService] + }); + + service = TestBed.inject(ToDoListService); + httpMock = TestBed.inject(HttpTestingController); + }); + + afterEach(() => { + httpMock.verify(); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); + + it('should return allToDoList by habitId on getHabitAllToDoLists', () => { + service.getHabitAllToDoLists(2, 'en').subscribe((data) => { + expect(data).toEqual(ALLUSERTODOLISTS); + }); + + const req = httpMock.expectOne(`${mainLink}habit/assign/2/allUserAndCustomList?lang=en`); + expect(req.request.responseType).toEqual('json'); + expect(req.request.method).toBe('GET'); + req.flush(ALLUSERTODOLISTS); + }); + + it('should return all user toDoList by lang on getUserToDoLists', () => { + service.getUserToDoLists('ua').subscribe((data) => { + expect(data).toEqual([ALLUSERTODOLISTS]); + }); + + const req = httpMock.expectOne(`${mainLink}habit/assign/allUserAndCustomToDoListsInprogress?lang=ua`); + expect(req.request.responseType).toEqual('json'); + expect(req.request.method).toBe('GET'); + req.flush([ALLUSERTODOLISTS]); + }); + + it('should update Standard ToDo Item Status', () => { + service.updateStandardToDoItemStatus(TODOLISTITEMTWO, 'ua').subscribe((data) => { + expect(data).toEqual([TODOLISTITEMTWO]); + }); + const req = httpMock.expectOne(`${mainLink}user/to-do-list-items/2/status/INPROGRESS?lang=ua`); + expect(req.request.method).toBe('PATCH'); + req.flush([TODOLISTITEMTWO]); + }); + + xit('should update Custom ToDo Item Status', () => { + service.updateCustomToDoItemStatus(1, TODOLISTITEMTWO).subscribe((data) => { + expect(data).toEqual(TODOLISTITEMTWO); + }); + const req = httpMock.expectOne(`${mainLink}custom/to-do-list-items/1/custom-to-do-list-items?itemId=2&status=INPROGRESS`); + expect(req.request.method).toBe('PATCH'); + req.flush(TODOLISTITEMTWO); + }); + + it('should update Habit ToDo List', () => { + service.updateHabitToDoList(UPDATEHABITTODOLIST).subscribe((data) => { + expect(data).toEqual(null); + }); + const req = httpMock.expectOne(`${mainLink}habit/assign/2/allUserAndCustomList?lang=ua`); + expect(req.request.method).toBe('PUT'); + req.flush(null); + }); +}); diff --git a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/to-do-list.service.ts b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/to-do-list.service.ts new file mode 100644 index 0000000000..5ff0618901 --- /dev/null +++ b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/to-do-list.service.ts @@ -0,0 +1,48 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { HttpClient } from '@angular/common/http'; +import { mainLink } from '../../../../../../links'; +import { AllToDoLists, HabitUpdateToDoList, ToDoList } from '@global-user/models/to-do-list.interface'; + +@Injectable({ + providedIn: 'root' +}) +export class ToDoListService { + constructor(private http: HttpClient) {} + + getHabitToDoList(habitId: number): Observable { + return this.http.get(`${mainLink}habit/${habitId}/to-do-list`); + } + + getHabitAllToDoLists(habitAssignId: number, lang: string): Observable { + return this.http.get(`${mainLink}habit/assign/${habitAssignId}/allUserAndCustomList?lang=${lang}`); + } + + // + getUserToDoLists(lang: string): Observable { + return this.http.get(`${mainLink}habit/assign/allUserAndCustomToDoListsInprogress?lang=${lang}`); + } + + updateStandardToDoItemStatus(item: ToDoList, lang: string): Observable { + const body = {}; + return this.http.patch(`${mainLink}user/to-do-list-items/${item.id}/status/${item.status}?lang=${lang}`, body); + } + + // + updateCustomToDoItemStatus(userId: number, item: ToDoList): Observable { + const body = {}; + return this.http.patch( + `${mainLink}custom/to-do-list-items/${userId}/custom-to-do-ping-list-items?itemId=${item.id}&status=${item.status}`, + body + ); + } + + updateHabitToDoList(habitToDoList: HabitUpdateToDoList) { + const assignId = habitToDoList.habitAssignId; + const body = { + customToDoListItemDto: habitToDoList.customToDoList, + userToDoListItemDto: habitToDoList.standardToDoList + }; + return this.http.put(`${mainLink}habit/assign/${assignId}/allUserAndCustomList?lang=${habitToDoList.lang}`, body); + } +} diff --git a/src/app/main/component/user/components/habit/all-habits/all-habits.component.spec.ts b/src/app/main/component/user/components/habit/all-habits/all-habits.component.spec.ts index bc68617a40..1906264791 100644 --- a/src/app/main/component/user/components/habit/all-habits/all-habits.component.spec.ts +++ b/src/app/main/component/user/components/habit/all-habits/all-habits.component.spec.ts @@ -84,7 +84,7 @@ describe('AllHabitsComponent', () => { rating: null, showEcoPlace: true, showLocation: true, - showShoppingList: true, + showToDoList: true, socialNetworks: [{ id: 1, url: defaultImagePath }] } as EditProfileModel; diff --git a/src/app/main/component/user/components/habit/const/data.const.ts b/src/app/main/component/user/components/habit/const/data.const.ts index 4829c7890b..0007332634 100644 --- a/src/app/main/component/user/components/habit/const/data.const.ts +++ b/src/app/main/component/user/components/habit/const/data.const.ts @@ -4,7 +4,7 @@ export const HABIT_TAGS_MAXLENGTH = 3; export const FIELD_SYMBOLS_LIMIT = 2048; -export const SHOPPING_ITEM_NAME_LIMIT = 20; +export const TO_DO_ITEM_NAME_LIMIT = 20; export const HABIT_COMPLEXITY_LIST = [ { value: 1, name: 'user.habit.add-new-habit.difficulty.easy', alt: 'Easy difficulty' }, @@ -23,7 +23,7 @@ export const STAR_IMAGES = { GREEN: 'assets/img/icon/star-1.png' }; -export const HABIT_SHOPPING_LIST_CHECK = { +export const HABIT_TO_DO_LIST_CHECK = { doneCheck: 'assets/icons/habits/filled-check-circle.svg', inprogressCheck: 'assets/icons/habits/lined-green-circle.svg', plusCheck: 'assets/icons/habits/doted-plus-green-circle.svg', diff --git a/src/app/main/component/user/components/habit/mocks/habit-assigned-mock.ts b/src/app/main/component/user/components/habit/mocks/habit-assigned-mock.ts index 9262fb9e98..3c7b676910 100644 --- a/src/app/main/component/user/components/habit/mocks/habit-assigned-mock.ts +++ b/src/app/main/component/user/components/habit/mocks/habit-assigned-mock.ts @@ -26,7 +26,7 @@ export const DEFAULTHABIT: HabitInterface = { id: 1, usersIdWhoCreatedCustomHabit: 33, image: 'https://www.testgreencity.ga/assets/img/habits/man.svg', - shoppingListItems: [], + toDoListItems: [], tags: [], isCustomHabit: false, isAssigned: false @@ -49,7 +49,7 @@ export const CUSTOMHABIT: HabitInterface = { id: 2, usersIdWhoCreatedCustomHabit: 50, image: '', - shoppingListItems: [], + toDoListItems: [], tags: [], isCustomHabit: true, isAssigned: false @@ -70,7 +70,7 @@ export const DEFAULTFULLINFOHABIT: HabitAssignInterface = { { enrollDate: '2023-04-14', id: 2 }, { enrollDate: '2023-04-10', id: 3 } ], - shoppingListItems: [ + toDoListItems: [ { id: 6, status: TodoStatus.active, @@ -95,7 +95,7 @@ export const CUSTOMFULLINFOHABIT: HabitAssignInterface = { { enrollDate: 'monday', id: 2 }, { enrollDate: 'wednesday', id: 3 } ], - shoppingListItems: [ + toDoListItems: [ { id: 6, status: TodoStatus.active, @@ -172,7 +172,7 @@ export const DEFAULTFULLINFOHABIT_2: HabitAssignInterface = { { enrollDate: '2023-04-14', id: 2 }, { enrollDate: '2023-04-10', id: 3 } ], - shoppingListItems: [ + toDoListItems: [ { id: 6, status: TodoStatus.active, diff --git a/src/app/main/component/user/components/habit/mocks/habit-mock.ts b/src/app/main/component/user/components/habit/mocks/habit-mock.ts index 3bdbde1b77..5bf49447f4 100644 --- a/src/app/main/component/user/components/habit/mocks/habit-mock.ts +++ b/src/app/main/component/user/components/habit/mocks/habit-mock.ts @@ -82,7 +82,7 @@ export const MOCK_CUSTOM_HABIT: CustomHabit = { duration: 30, tagIds: [1, 2], image: 'testImage', - shopList: [ + toDoList: [ { id: 2, text: 'Collapsible Silicone Water Bottle', @@ -107,7 +107,7 @@ export const MOCK_CUSTOM_HABIT_RESPONSE: CustomHabitDtoRequest = { defaultDuration: MOCK_CUSTOM_HABIT.duration, image: MOCK_CUSTOM_HABIT.image, tagIds: MOCK_CUSTOM_HABIT.tagIds, - customShoppingListItemDto: MOCK_CUSTOM_HABIT.shopList + customToDoListItemDto: MOCK_CUSTOM_HABIT.toDoList }; export const NEW_HABIT_ARRAY_MOCK: NewHabitDto[] = [new NewHabitDto(1), new NewHabitDto(2), new NewHabitDto(3)]; diff --git a/src/app/main/component/user/components/habit/mocks/shopping-list-mock.ts b/src/app/main/component/user/components/habit/mocks/to-do-list-mock.ts similarity index 73% rename from src/app/main/component/user/components/habit/mocks/shopping-list-mock.ts rename to src/app/main/component/user/components/habit/mocks/to-do-list-mock.ts index 490c47b531..b280cef10f 100644 --- a/src/app/main/component/user/components/habit/mocks/shopping-list-mock.ts +++ b/src/app/main/component/user/components/habit/mocks/to-do-list-mock.ts @@ -1,36 +1,36 @@ -import { AllShoppingLists, CustomShoppingItem, HabitUpdateShopList, ShoppingList } from '@user-models/shoppinglist.interface'; +import { AllToDoLists, CustomToDoItem, HabitUpdateToDoList, ToDoList } from '@global-user/models/to-do-list.interface'; import { TodoStatus } from '../models/todo-status.enum'; import { HabitListInterface } from '@global-user/components/habit/models/interfaces/habit.interface'; import { CustomHabit, CustomHabitDtoRequest } from '@global-user/components/habit/models/interfaces/custom-habit.interface'; import { FriendProfilePicturesArrayModel } from '@user-models/friend.model'; -export const SHOPLISTITEMONE: ShoppingList = { +export const TODOLISTITEMONE: ToDoList = { id: 1, text: 'Reusable stainless steel water bottle', status: TodoStatus.active }; -export const SHOPLISTITEMTWO: ShoppingList = { +export const TODOLISTITEMTWO: ToDoList = { id: 2, text: 'Collapsible Silicone Water Bottle', status: TodoStatus.inprogress }; -export const SHOPLIST: ShoppingList[] = [SHOPLISTITEMONE, SHOPLISTITEMTWO]; +export const TODOLIST: ToDoList[] = [TODOLISTITEMONE, TODOLISTITEMTWO]; -export const ALLUSERSHOPLISTS: AllShoppingLists = { - userShoppingListItemDto: [SHOPLISTITEMONE], - customShoppingListItemDto: [SHOPLISTITEMTWO] +export const ALLUSERTODOLISTS: AllToDoLists = { + userToDoListItemDto: [TODOLISTITEMONE], + customToDoListItemDto: [TODOLISTITEMTWO] }; -export const UPDATEHABITSHOPLIST: HabitUpdateShopList = { +export const UPDATEHABITTODOLIST: HabitUpdateToDoList = { habitAssignId: 2, - standardShopList: [SHOPLISTITEMONE], - customShopList: [SHOPLISTITEMTWO], + standardToDoList: [TODOLISTITEMONE], + customToDoList: [TODOLISTITEMTWO], lang: 'ua' }; -export const CUSTOMSHOPITEM: CustomShoppingItem = { +export const CUSTOMTODOITEM: CustomToDoItem = { text: 'New item' }; @@ -57,8 +57,8 @@ export const MOCK_HABITS: HabitListInterface = { habitAssignStatus: 'testStatus', isCustomHabit: true, usersIdWhoCreatedCustomHabit: 1, - customShoppingListItems: [], - shoppingListItems: [], + customToDoListItems: [], + toDoListItems: [], tags: ['tag1', 'tag2'] } ], @@ -73,7 +73,7 @@ export const MOCK_CUSTOM_HABIT: CustomHabit = { duration: 30, tagIds: [1, 2], image: 'testImage', - shopList: ALLUSERSHOPLISTS.customShoppingListItemDto + toDoList: ALLUSERTODOLISTS.customToDoListItemDto }; export const MOCK_CUSTOM_HABIT_RESPONSE: CustomHabitDtoRequest = { @@ -92,7 +92,7 @@ export const MOCK_CUSTOM_HABIT_RESPONSE: CustomHabitDtoRequest = { defaultDuration: MOCK_CUSTOM_HABIT.duration, image: MOCK_CUSTOM_HABIT.image, tagIds: MOCK_CUSTOM_HABIT.tagIds, - customShoppingListItemDto: MOCK_CUSTOM_HABIT.shopList + customToDoListItemDto: MOCK_CUSTOM_HABIT.toDoList }; export const MOCK_FRIEND_PROFILE_PICTURES: FriendProfilePicturesArrayModel[] = [ diff --git a/src/app/main/component/user/components/habit/models/interfaces/custom-habit.interface.ts b/src/app/main/component/user/components/habit/models/interfaces/custom-habit.interface.ts index 45601b36b1..2cb1d0e92e 100644 --- a/src/app/main/component/user/components/habit/models/interfaces/custom-habit.interface.ts +++ b/src/app/main/component/user/components/habit/models/interfaces/custom-habit.interface.ts @@ -1,4 +1,4 @@ -import { ShoppingList } from '@user-models/shoppinglist.interface'; +import { ToDoList } from '@global-user/models/to-do-list.interface'; import { HabitTranslationInterface } from './habit.interface'; export interface CustomHabitDtoRequest { @@ -7,7 +7,7 @@ export interface CustomHabitDtoRequest { defaultDuration: number; image: string; tagIds: number[]; - customShoppingListItemDto: ShoppingList[]; + customToDoListItemDto: ToDoList[]; id?: number; userId?: number; } @@ -19,5 +19,5 @@ export interface CustomHabit { duration: number; tagIds: number[]; image: string; - shopList: ShoppingList[]; + toDoList: ToDoList[]; } diff --git a/src/app/main/component/user/components/habit/models/interfaces/habit-assign.interface.ts b/src/app/main/component/user/components/habit/models/interfaces/habit-assign.interface.ts index 11fadba3f2..e4e3f8037d 100644 --- a/src/app/main/component/user/components/habit/models/interfaces/habit-assign.interface.ts +++ b/src/app/main/component/user/components/habit/models/interfaces/habit-assign.interface.ts @@ -1,5 +1,5 @@ import { HabitStatus } from '@global-models/habit/HabitStatus.enum'; -import { ShoppingList } from '@user-models/shoppinglist.interface'; +import { ToDoList } from '@global-user/models/to-do-list.interface'; import { HabitInterface } from './habit.interface'; export interface HabitAssignInterface { @@ -16,7 +16,7 @@ export interface HabitAssignInterface { habitStreak: number; lastEnrollmentDate: Date; habitStatusCalendarDtoList: Array; - shoppingListItems: Array; + toDoListItems: Array; progressNotificationHasDisplayed?: boolean; } diff --git a/src/app/main/component/user/components/habit/models/interfaces/habit.interface.ts b/src/app/main/component/user/components/habit/models/interfaces/habit.interface.ts index 2ca88d2ffa..464574d58c 100644 --- a/src/app/main/component/user/components/habit/models/interfaces/habit.interface.ts +++ b/src/app/main/component/user/components/habit/models/interfaces/habit.interface.ts @@ -1,4 +1,4 @@ -import { ShoppingList } from '@user-models/shoppinglist.interface'; +import { ToDoList } from '@global-user/models/to-do-list.interface'; export interface HabitInterface { defaultDuration: number; @@ -12,8 +12,8 @@ export interface HabitInterface { habitAssignStatus?: string; isCustomHabit: boolean; usersIdWhoCreatedCustomHabit: number; - customShoppingListItems?: ShoppingList[]; - shoppingListItems?: ShoppingList[]; + customToDoListItems?: ToDoList[]; + toDoListItems?: ToDoList[]; tags: Array; duration?: number; } diff --git a/src/app/main/component/user/components/index.ts b/src/app/main/component/user/components/index.ts index d511b52fa1..ba84fa28a4 100644 --- a/src/app/main/component/user/components/index.ts +++ b/src/app/main/component/user/components/index.ts @@ -23,5 +23,5 @@ export { OneHabitComponent } from './profile/profile-dashboard/one-habit/one-hab export { ProfileWidgetComponent } from './profile/profile-widget/profile-widget.component'; export { ProfileHeaderComponent } from './profile/profile-widget/profile-header/profile-header.component'; export { ProfileProgressComponent } from './profile/profile-widget/profile-progress/profile-progress.component'; -export { ShoppingListComponent } from './profile/shopping-list/shopping-list.component'; +export { ToDoListComponent } from './profile/to-do-list/to-do-list.component'; export { UserSettingComponent } from './user-setting/user-setting.component'; diff --git a/src/app/main/component/user/components/profile/edit-profile/edit-profile-form-builder.ts b/src/app/main/component/user/components/profile/edit-profile/edit-profile-form-builder.ts index e31a5b7c77..3594c51be5 100644 --- a/src/app/main/component/user/components/profile/edit-profile/edit-profile-form-builder.ts +++ b/src/app/main/component/user/components/profile/edit-profile/edit-profile-form-builder.ts @@ -19,7 +19,7 @@ export class EditProfileFormBuilder { credo: ['', Validators.maxLength(170)], showLocation: [false], showEcoPlace: [false], - showShoppingList: [false], + showToDoList: [false], socialNetworks: [''], emailPreferences: this.createEmailPreferencesGroup(null) }); @@ -94,7 +94,7 @@ export class EditProfileFormBuilder { credo: [editForm.userCredo, Validators.maxLength(170)], showLocation: [editForm.showLocation], showEcoPlace: [editForm.showEcoPlace], - showShoppingList: [editForm.showShoppingList], + showToDoList: [editForm.showToDoList], socialNetworks: [editForm.socialNetworks], emailPreferences: this.createEmailPreferencesGroup(editForm.notificationPreferences) }); diff --git a/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.html b/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.html index 6c12b1a315..4697dff660 100644 --- a/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.html +++ b/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.html @@ -67,9 +67,9 @@

    {{ 'user.edit-profile.edit-profile' | translate }}

diff --git a/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.spec.ts b/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.spec.ts index 20960589f4..e86958df65 100644 --- a/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.spec.ts +++ b/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.spec.ts @@ -186,7 +186,7 @@ describe('EditProfileComponent', () => { userCredo: '', showLocation: '', showEcoPlace: '', - showShoppingList: '', + showToDoList: '', socialNetworks: [] }; component.editProfileForm.value.city = ''; @@ -194,7 +194,7 @@ describe('EditProfileComponent', () => { component.editProfileForm.value.credo = ''; component.editProfileForm.value.showLocation = ''; component.editProfileForm.value.showEcoPlace = ''; - component.editProfileForm.value.showShoppingList = ''; + component.editProfileForm.value.showToDoList = ''; component.socialNetworksToServer = []; }); @@ -264,7 +264,7 @@ describe('EditProfileComponent', () => { rating: 658, showEcoPlace: true, showLocation: true, - showShoppingList: true, + showToDoList: true, socialNetworks: [{ id: 220, url: 'http://instagram.com/profile' }] } as EditProfileModel; }); diff --git a/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts b/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts index 04cdf06730..b1d891c3d5 100644 --- a/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts +++ b/src/app/main/component/user/components/profile/edit-profile/edit-profile.component.ts @@ -110,7 +110,7 @@ export class EditProfileComponent extends FormBaseComponent implements OnInit, O userCredo: this.editProfileForm.value.credo === null ? '' : this.editProfileForm.value.credo, showLocation: this.editProfileForm.value.showLocation, showEcoPlace: this.editProfileForm.value.showEcoPlace, - showShoppingList: this.editProfileForm.value.showShoppingList, + showToDoList: this.editProfileForm.value.showToDoList, socialNetworks: this.socialNetworksToServer }; } @@ -133,7 +133,7 @@ export class EditProfileComponent extends FormBaseComponent implements OnInit, O }, showLocation: data.showLocation, showEcoPlace: data.showEcoPlace, - showShoppingList: data.showShoppingList, + showToDoList: data.showToDoList, socialNetworks: data.socialNetworks.map((network) => network.url) }; this.editProfileForm.markAllAsTouched(); @@ -197,7 +197,7 @@ export class EditProfileComponent extends FormBaseComponent implements OnInit, O userCredo: form.value.credo, showLocation: !!form.value.showLocation, showEcoPlace: !!form.value.showEcoPlace, - showShoppingList: !!form.value.showShoppingList, + showToDoList: !!form.value.showToDoList, socialNetworks: this.socialNetworksToServer, emailPreferences: emailPreferences.length > 0 ? emailPreferences : null }; diff --git a/src/app/main/component/user/components/profile/profile-service/profile.service.spec.ts b/src/app/main/component/user/components/profile/profile-service/profile.service.spec.ts index adc04163df..4466570708 100644 --- a/src/app/main/component/user/components/profile/profile-service/profile.service.spec.ts +++ b/src/app/main/component/user/components/profile/profile-service/profile.service.spec.ts @@ -83,7 +83,7 @@ describe('ProfileService', () => { rating: 1999, showEcoPlace: true, showLocation: false, - showShoppingList: true, + showToDoList: true, socialNetworks: [] }; diff --git a/src/app/main/component/user/components/profile/profile-widget/profile-header/profile-header.component.spec.ts b/src/app/main/component/user/components/profile/profile-widget/profile-header/profile-header.component.spec.ts index 28c4438fd0..6089246f83 100644 --- a/src/app/main/component/user/components/profile/profile-widget/profile-header/profile-header.component.spec.ts +++ b/src/app/main/component/user/components/profile/profile-widget/profile-header/profile-header.component.spec.ts @@ -58,7 +58,7 @@ describe('ProfileHeaderComponent', () => { rating: 2, showEcoPlace: false, showLocation: false, - showShoppingList: false, + showToDoList: false, socialNetworks: [{ id: 220, url: 'http://instagram' }] } as EditProfileModel; fixture.detectChanges(); diff --git a/src/app/main/component/user/components/profile/profile.component.html b/src/app/main/component/user/components/profile/profile.component.html index 33b686a781..4ecd2c0692 100644 --- a/src/app/main/component/user/components/profile/profile.component.html +++ b/src/app/main/component/user/components/profile/profile.component.html @@ -6,7 +6,7 @@ - +
@@ -15,7 +15,7 @@ - +
diff --git a/src/app/main/component/user/components/profile/profile.component.scss b/src/app/main/component/user/components/profile/profile.component.scss index 09f9f90604..5e63d4ba32 100644 --- a/src/app/main/component/user/components/profile/profile.component.scss +++ b/src/app/main/component/user/components/profile/profile.component.scss @@ -153,7 +153,7 @@ .profile-wrapper { .right-column { - app-shopping-list { + app-to-do-list { display: none; } } @@ -174,13 +174,13 @@ display: flex; } - .app-shopping-list { + .app-to-do-list { display: none; } } .right-column { - app-shopping-list { + app-to-do-list { margin-top: 50px; margin-bottom: 24px; } @@ -191,13 +191,13 @@ @include responsiveRange(md, xl) { .profile-wrapper { .left-column { - .app-shopping-list { + .app-to-do-list { display: block; } } .right-column { - .app-shopping-list { + .app-to-do-list { display: none; } } @@ -207,13 +207,13 @@ @include responsiveMobileFirst(xl) { .profile-wrapper { .left-column { - .app-shopping-list { + .app-to-do-list { display: none; } } .right-column { - .app-shopping-list { + .app-to-do-list { display: block; margin-top: 16px; } diff --git a/src/app/main/component/user/components/profile/profile.component.spec.ts b/src/app/main/component/user/components/profile/profile.component.spec.ts index da6c7d7bbb..36a74f5e63 100644 --- a/src/app/main/component/user/components/profile/profile.component.spec.ts +++ b/src/app/main/component/user/components/profile/profile.component.spec.ts @@ -14,7 +14,7 @@ describe('ProfileComponent', () => { const fakeItem = { city: 'fakeCity', - showShoppingList: false + showToDoList: false }; const liveAnnouncerMock = jasmine.createSpyObj('announcer', ['announce']); const localStorageServiceMock = jasmine.createSpyObj('localStorageService', ['getCurrentLanguage', 'setCurentPage']); diff --git a/src/app/main/component/user/components/profile/shopping-list/shopping-list.component.html b/src/app/main/component/user/components/profile/shopping-list/shopping-list.component.html deleted file mode 100644 index 91cf2cba9b..0000000000 --- a/src/app/main/component/user/components/profile/shopping-list/shopping-list.component.html +++ /dev/null @@ -1,42 +0,0 @@ -
-
-
-
- {{ 'profile.to-do-list' | translate }} -
-
{{ shoppingList?.length }} {{ 'profile.elements' | correctUnit: shoppingList?.length:currentLang | translate }} -
-
- {{ - (toggle ? 'user.habit.btn.see-less' : 'user.habit.btn.see-all') | translate - }} -
-
- -
-
-
- -
-
-
-

{{ 'profile.empty-list' | translate }}

-
-
-
diff --git a/src/app/main/component/user/components/profile/shopping-list/shopping-list.component.ts b/src/app/main/component/user/components/profile/shopping-list/shopping-list.component.ts deleted file mode 100644 index 43f38758d4..0000000000 --- a/src/app/main/component/user/components/profile/shopping-list/shopping-list.component.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { catchError, takeUntil } from 'rxjs/operators'; -import { Component, OnInit, ChangeDetectorRef } from '@angular/core'; -import { of, Subject } from 'rxjs'; -import { Patterns } from 'src/assets/patterns/patterns'; -import { ShoppingListService } from '@global-user/components/habit/add-new-habit/habit-edit-shopping-list/shopping-list.service'; -import { LocalStorageService } from '@global-service/localstorage/local-storage.service'; -import { Subscription } from 'stompjs'; -import { AllShoppingLists, ShoppingList } from '@global-user/models/shoppinglist.interface'; -import { TodoStatus } from '@global-user/components/habit/models/todo-status.enum'; - -@Component({ - selector: 'app-shopping-list', - templateUrl: './shopping-list.component.html', - styleUrls: ['./shopping-list.component.scss'] -}) -export class ShoppingListComponent implements OnInit { - shoppingList: ShoppingList[] = []; - toggle: boolean; - private userId: number; - currentLang: string; - profileSubscription: Subscription; - private shoppingListCache: AllShoppingLists[] | null = null; - private destroy$: Subject = new Subject(); - - constructor( - private localStorageService: LocalStorageService, - private shopListService: ShoppingListService, - private cdr: ChangeDetectorRef - ) {} - - ngOnInit(): void { - this.userId = this.localStorageService.getUserId(); - this.subscribeToLangChange(); - } - - private subscribeToLangChange(): void { - this.localStorageService.languageBehaviourSubject.subscribe((lang: string) => { - this.currentLang = lang; - if (this.localStorageService.getUserId()) { - this.getAllShopLists(); - } - }); - } - - private getAllShopLists(): void { - if (this.shoppingListCache) { - this.updateShoppingList(this.shoppingListCache); - return; - } - - this.shopListService - .getUserShoppingLists(this.currentLang) - .pipe( - takeUntil(this.destroy$), - catchError(() => of([])) - ) - .subscribe((list) => { - this.shoppingListCache = list; - this.updateShoppingList(list); - }); - } - - private updateShoppingList(list: AllShoppingLists[]): void { - const customShopList = this.convertShopList(list, 'custom'); - const standardShopList = this.convertShopList(list, 'standard'); - customShopList.forEach((el) => (el.custom = true)); - this.shoppingList = [...customShopList, ...standardShopList]; - } - - convertShopList(list: AllShoppingLists[], type: string): ShoppingList[] { - return list.reduce((acc, obj) => acc.concat(type === 'custom' ? obj.customShoppingListItemDto : obj.userShoppingListItemDto), []); - } - - isValidURL(url: string): boolean { - return Patterns.isValidURL.test(url); - } - - openCloseList(): void { - this.toggle = !this.toggle; - } - - toggleDone(item: ShoppingList): void { - item.status = item.status === TodoStatus.inprogress ? TodoStatus.done : TodoStatus.inprogress; - item.custom ? this.updateStatusCustomItem(item) : this.updateStatusItem(item); - } - - private updateStatusItem(item: ShoppingList): void { - this.shopListService - .updateStandardShopItemStatus(item, this.currentLang) - .pipe(takeUntil(this.destroy$)) - .subscribe(() => { - this.updateShopList(item); - }); - } - - private updateStatusCustomItem(item: ShoppingList): void { - this.shopListService - .updateCustomShopItemStatus(this.userId, item) - .pipe(takeUntil(this.destroy$)) - .subscribe(() => { - this.updateShopList(item); - }); - } - - private updateShopList(item: ShoppingList): void { - this.shoppingList = this.shoppingList.map((el) => (el.id === item.id ? { ...el, status: item.status } : el)); - this.cdr.detectChanges(); - } -} diff --git a/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.html b/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.html new file mode 100644 index 0000000000..b4ccfba4f7 --- /dev/null +++ b/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.html @@ -0,0 +1,40 @@ +
+
+
+
+ {{ 'profile.to-do-list' | translate }} +
+
{{ toDoList?.length }} {{ 'profile.elements' | correctUnit: toDoList?.length : currentLang | translate }} +
+
+ {{ + (toggle ? 'user.habit.btn.see-less' : 'user.habit.btn.see-all') | translate + }} +
+
+ +
+
+
+ +
+
+
+

{{ 'profile.empty-list' | translate }}

+
+
+
diff --git a/src/app/main/component/user/components/profile/shopping-list/shopping-list.component.scss b/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.scss similarity index 93% rename from src/app/main/component/user/components/profile/shopping-list/shopping-list.component.scss rename to src/app/main/component/user/components/profile/to-do-list/to-do-list.component.scss index 3166262899..bed0c57202 100644 --- a/src/app/main/component/user/components/profile/shopping-list/shopping-list.component.scss +++ b/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.scss @@ -7,12 +7,12 @@ box-shadow: 1px 4px 8px var(--quintynary-dark-grey); } -.shopping-list-block { +.to-do-list-block { width: 213px; margin: 0 auto; } -.shopping-list-content { +.to-do-list-content { padding-top: 24px; font-family: var(--tertiary-font); font-style: normal; @@ -86,15 +86,15 @@ h2 > span { text-decoration: line-through; } -.shopping-list-min { +.to-do-list-min { height: 90px; } -.shopping-list-max { +.to-do-list-max { height: max-content; } -.shopping-list { +.to-do-list { width: 100%; padding: 5px 0 0; overflow-x: hidden; @@ -138,7 +138,7 @@ h2 > span { } @include responsiveRange(md, 2xl) { - .shopping-list-block { + .to-do-list-block { border-top: 1px solid var(--quaternary-light-grey); width: 184px; } @@ -149,7 +149,7 @@ h2 > span { margin-top: 20px; } - .shopping-list-block { + .to-do-list-block { width: 100%; padding: 0 16px; } diff --git a/src/app/main/component/user/components/profile/shopping-list/shopping-list.component.spec.ts b/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.spec.ts similarity index 55% rename from src/app/main/component/user/components/profile/shopping-list/shopping-list.component.spec.ts rename to src/app/main/component/user/components/profile/to-do-list/to-do-list.component.spec.ts index 3ff2b31661..4cbf3872db 100644 --- a/src/app/main/component/user/components/profile/shopping-list/shopping-list.component.spec.ts +++ b/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.spec.ts @@ -1,24 +1,24 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; -import { ShoppingListComponent } from '@global-user/components'; +import { ToDoListComponent } from '@global-user/components'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { TranslateModule } from '@ngx-translate/core'; import { LocalStorageService } from '@global-service/localstorage/local-storage.service'; import { of, BehaviorSubject } from 'rxjs'; import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { ShoppingListService } from '@global-user/components/habit/add-new-habit/habit-edit-shopping-list/shopping-list.service'; +import { ToDoListService } from '@global-user/components/habit/add-new-habit/habit-edit-to-do-list/to-do-list.service'; import { Language } from 'src/app/main/i18n/Language'; -import { SHOPLISTITEMONE, SHOPLISTITEMTWO } from '@global-user/components/habit/mocks/shopping-list-mock'; -import { SHOPLIST } from '@global-user/components/habit/mocks/shopping-list-mock'; -import { ALLUSERSHOPLISTS } from '@global-user/components/habit/mocks/shopping-list-mock'; +import { TODOLISTITEMONE, TODOLISTITEMTWO } from '@global-user/components/habit/mocks/to-do-list-mock'; +import { TODOLIST } from '@global-user/components/habit/mocks/to-do-list-mock'; +import { ALLUSERTODOLISTS } from '@global-user/components/habit/mocks/to-do-list-mock'; import { CorrectUnitPipe } from 'src/app/shared/correct-unit-pipe/correct-unit.pipe'; import { TodoStatus } from '@global-user/components/habit/models/todo-status.enum'; import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; -describe('ShoppingListComponent', () => { - let component: ShoppingListComponent; - let fixture: ComponentFixture; +describe('ToDoListComponent', () => { + let component: ToDoListComponent; + let fixture: ComponentFixture; const localStorageServiceMock = jasmine.createSpyObj('localStorageService', [ 'languageBehaviourSubject', @@ -30,18 +30,18 @@ describe('ShoppingListComponent', () => { localStorageServiceMock.languageSubject = of('en'); localStorageServiceMock.getUserId = () => 1; - const shoppingListServiceMock: ShoppingListService = jasmine.createSpyObj('fakeShoppingListService', [ - 'getUserShoppingLists', - 'updateStandardShopItemStatus', - 'updateCustomShopItemStatus' + const toDoListServiceMock: ToDoListService = jasmine.createSpyObj('fakeToDoListService', [ + 'getUserToDoLists', + 'updateStandardToDoItemStatus', + 'updateCustomToDoItemStatus' ]); - shoppingListServiceMock.getUserShoppingLists = () => of([ALLUSERSHOPLISTS]); - shoppingListServiceMock.updateStandardShopItemStatus = () => of(); - shoppingListServiceMock.updateCustomShopItemStatus = () => of(); + toDoListServiceMock.getUserToDoLists = () => of([ALLUSERTODOLISTS]); + toDoListServiceMock.updateStandardToDoItemStatus = () => of(); + toDoListServiceMock.updateCustomToDoItemStatus = () => of(); beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ - declarations: [ShoppingListComponent, CorrectUnitPipe], + declarations: [ToDoListComponent, CorrectUnitPipe], imports: [ RouterTestingModule, HttpClientTestingModule, @@ -51,7 +51,7 @@ describe('ShoppingListComponent', () => { NgbModule ], providers: [ - { provide: ShoppingListService, useValue: shoppingListServiceMock }, + { provide: ToDoListService, useValue: toDoListServiceMock }, { provide: LocalStorageService, useValue: localStorageServiceMock } ], schemas: [CUSTOM_ELEMENTS_SCHEMA] @@ -59,7 +59,7 @@ describe('ShoppingListComponent', () => { })); beforeEach(() => { - fixture = TestBed.createComponent(ShoppingListComponent); + fixture = TestBed.createComponent(ToDoListComponent); component = fixture.componentInstance; fixture.detectChanges(); }); @@ -68,20 +68,20 @@ describe('ShoppingListComponent', () => { expect(component).toBeTruthy(); }); - it('should set custom true after getShopLists', () => { + it('should set custom true after getToDoLists', () => { const result = [ - { ...SHOPLISTITEMONE, custom: true }, - { ...SHOPLISTITEMTWO, custom: true } + { ...TODOLISTITEMONE, custom: true }, + { ...TODOLISTITEMTWO, custom: true } ]; - SHOPLIST.forEach((el) => (el.custom = true)); - component.shoppingList = SHOPLIST; - expect(component.shoppingList).toEqual(result); + TODOLIST.forEach((el) => (el.custom = true)); + component.toDoList = TODOLIST; + expect(component.toDoList).toEqual(result); }); - it('should set shopList after getShopList', () => { - component.shoppingList = []; - component.shoppingList = [...component.shoppingList, ...SHOPLIST]; - expect(component.shoppingList).toEqual(SHOPLIST); + it('should set toDoList after getToDoList', () => { + component.toDoList = []; + component.toDoList = [...component.toDoList, ...TODOLIST]; + expect(component.toDoList).toEqual(TODOLIST); }); it('should change toogle from true on openCloseList', () => { @@ -97,8 +97,8 @@ describe('ShoppingListComponent', () => { }); it('should change item status on toggleDone', () => { - SHOPLISTITEMONE.status = TodoStatus.inprogress; - component.toggleDone(SHOPLISTITEMONE); - expect(SHOPLISTITEMONE.status).toBe('DONE'); + TODOLISTITEMONE.status = TodoStatus.inprogress; + component.toggleDone(TODOLISTITEMONE); + expect(TODOLISTITEMONE.status).toBe('DONE'); }); }); diff --git a/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.ts b/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.ts new file mode 100644 index 0000000000..3659bd7848 --- /dev/null +++ b/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.ts @@ -0,0 +1,109 @@ +import { catchError, takeUntil } from 'rxjs/operators'; +import { Component, OnInit, ChangeDetectorRef } from '@angular/core'; +import { of, Subject } from 'rxjs'; +import { Patterns } from 'src/assets/patterns/patterns'; +import { ToDoListService } from '@global-user/components/habit/add-new-habit/habit-edit-to-do-list/to-do-list.service'; +import { LocalStorageService } from '@global-service/localstorage/local-storage.service'; +import { Subscription } from 'stompjs'; +import { AllToDoLists, ToDoList } from '@global-user/models/to-do-list.interface'; +import { TodoStatus } from '@global-user/components/habit/models/todo-status.enum'; + +@Component({ + selector: 'app-to-do-list', + templateUrl: './to-do-list.component.html', + styleUrls: ['./to-do-list.component.scss'] +}) +export class ToDoListComponent implements OnInit { + toDoList: ToDoList[] = []; + toggle: boolean; + private userId: number; + currentLang: string; + profileSubscription: Subscription; + private toDoListCache: AllToDoLists[] | null = null; + private destroy$: Subject = new Subject(); + + constructor( + private localStorageService: LocalStorageService, + private toDoListService: ToDoListService, + private cdr: ChangeDetectorRef + ) {} + + ngOnInit(): void { + this.userId = this.localStorageService.getUserId(); + this.subscribeToLangChange(); + } + + private subscribeToLangChange(): void { + this.localStorageService.languageBehaviourSubject.subscribe((lang: string) => { + this.currentLang = lang; + if (this.localStorageService.getUserId()) { + this.getAllToDoLists(); + } + }); + } + + private getAllToDoLists(): void { + if (this.toDoListCache) { + this.updateAllToDoList(this.toDoListCache); + return; + } + + this.toDoListService + .getUserToDoLists(this.currentLang) + .pipe( + takeUntil(this.destroy$), + catchError(() => of([])) + ) + .subscribe((list) => { + this.toDoListCache = list; + this.updateAllToDoList(list); + }); + } + + private updateAllToDoList(list: AllToDoLists[]): void { + const customToDoList = this.convertToDoList(list, 'custom'); + const standardToDoList = this.convertToDoList(list, 'standard'); + customToDoList.forEach((el) => (el.custom = true)); + this.toDoList = [...customToDoList, ...standardToDoList]; + } + + convertToDoList(list: AllToDoLists[], type: string): ToDoList[] { + return list.reduce((acc, obj) => acc.concat(type === 'custom' ? obj.customToDoListItemDto : obj.userToDoListItemDto), []); + } + + isValidURL(url: string): boolean { + return Patterns.isValidURL.test(url); + } + + openCloseList(): void { + this.toggle = !this.toggle; + } + + toggleDone(item: ToDoList): void { + item.status = item.status === TodoStatus.inprogress ? TodoStatus.done : TodoStatus.inprogress; + item.custom ? this.updateStatusCustomItem(item) : this.updateStatusItem(item); + } + + private updateStatusItem(item: ToDoList): void { + this.toDoListService + .updateStandardToDoItemStatus(item, this.currentLang) + .pipe(takeUntil(this.destroy$)) + .subscribe(() => { + this.updateToDoList(item); + }); + } + + private updateStatusCustomItem(item: ToDoList): void { + this.toDoListService + .updateCustomToDoItemStatus(this.userId, item) + .pipe(takeUntil(this.destroy$)) + .subscribe(() => { + this.updateToDoList(item); + }); + } + + private updateToDoList(item: ToDoList): void { + this.toDoList = this.toDoList.map((el) => (el.id === item.id ? { ...el, status: item.status } : el)); + this.cdr.detectChanges(); + } +} diff --git a/src/app/main/component/user/components/profile/users-friends/friend-dashboard/friend-profile-page/friend-profile-page.component.html b/src/app/main/component/user/components/profile/users-friends/friend-dashboard/friend-profile-page/friend-profile-page.component.html index 7faa61b377..88c1a4ff0a 100644 --- a/src/app/main/component/user/components/profile/users-friends/friend-dashboard/friend-profile-page/friend-profile-page.component.html +++ b/src/app/main/component/user/components/profile/users-friends/friend-dashboard/friend-profile-page/friend-profile-page.component.html @@ -7,7 +7,7 @@
- +
diff --git a/src/app/main/component/user/components/profile/users-friends/friend-dashboard/friend-profile-page/friend-profile-page.component.scss b/src/app/main/component/user/components/profile/users-friends/friend-dashboard/friend-profile-page/friend-profile-page.component.scss index 6e33e98830..9002de6533 100644 --- a/src/app/main/component/user/components/profile/users-friends/friend-dashboard/friend-profile-page/friend-profile-page.component.scss +++ b/src/app/main/component/user/components/profile/users-friends/friend-dashboard/friend-profile-page/friend-profile-page.component.scss @@ -76,7 +76,7 @@ @include responsiveMobileFirst(xl) { .profile-wrapper { .left-column { - .app-shopping-list { + .app-to-do-list { display: none; } } diff --git a/src/app/main/component/user/models/edit-profile.model.ts b/src/app/main/component/user/models/edit-profile.model.ts index cf8654c222..f84b8bcd3e 100644 --- a/src/app/main/component/user/models/edit-profile.model.ts +++ b/src/app/main/component/user/models/edit-profile.model.ts @@ -6,7 +6,7 @@ export class EditProfileModel { rating: number | null; showEcoPlace: boolean; showLocation: boolean; - showShoppingList: boolean; + showToDoList: boolean; socialNetworks: Array<{ id: number; url: string }>; notificationPreferences: NotificationPreference[]; } @@ -17,7 +17,7 @@ export class EditProfileDto { userCredo: string; showEcoPlace: boolean; showLocation: boolean; - showShoppingList: boolean; + showToDoList: boolean; socialNetworks: Array; emailPreferences: NotificationPreference[]; } diff --git a/src/app/main/component/user/models/shoppinglist.interface.ts b/src/app/main/component/user/models/shoppinglist.interface.ts deleted file mode 100644 index c65e0db816..0000000000 --- a/src/app/main/component/user/models/shoppinglist.interface.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { TodoStatus } from '@global-user/components/habit/models/todo-status.enum'; - -export interface ShoppingList { - id: null | number; - status: TodoStatus; - text: string; - selected?: boolean; - custom?: boolean; -} - -export interface AllShoppingLists { - userShoppingListItemDto: ShoppingList[]; - customShoppingListItemDto: ShoppingList[]; -} - -export interface CustomShoppingItem { - text: string; -} - -export interface HabitUpdateShopList { - habitAssignId: number; - standardShopList: ShoppingList[]; - customShopList: ShoppingList[]; - lang: string; -} diff --git a/src/app/main/component/user/models/to-do-list.interface.ts b/src/app/main/component/user/models/to-do-list.interface.ts new file mode 100644 index 0000000000..a99e67747e --- /dev/null +++ b/src/app/main/component/user/models/to-do-list.interface.ts @@ -0,0 +1,25 @@ +import { TodoStatus } from '@global-user/components/habit/models/todo-status.enum'; + +export interface ToDoList { + id: null | number; + status: TodoStatus; + text: string; + selected?: boolean; + custom?: boolean; +} + +export interface AllToDoLists { + userToDoListItemDto: ToDoList[]; + customToDoListItemDto: ToDoList[]; +} + +export interface CustomToDoItem { + text: string; +} + +export interface HabitUpdateToDoList { + habitAssignId: number; + standardToDoList: ToDoList[]; + customToDoList: ToDoList[]; + lang: string; +} diff --git a/src/app/main/component/user/user.module.ts b/src/app/main/component/user/user.module.ts index b458ae9ac9..af9ff5ecd0 100644 --- a/src/app/main/component/user/user.module.ts +++ b/src/app/main/component/user/user.module.ts @@ -31,11 +31,11 @@ import { ProfileWidgetComponent, ProfileHeaderComponent, ProfileProgressComponent, - ShoppingListComponent, UserSettingComponent, EditProfileComponent, PersonalPhotoComponent, - SocialNetworksComponent + SocialNetworksComponent, + ToDoListComponent } from './components'; import { ShowFirstNLettersPipe } from '@pipe/show-first-n-letters/show-first-n-letters.pipe'; import { ShowFirstNPipe } from '@pipe/show-first-n-pipe/show-first-n.pipe'; @@ -55,7 +55,7 @@ import { InfiniteScrollModule } from 'ngx-infinite-scroll'; import { HabitProgressComponent } from './components/habit/add-new-habit/habit-progress/habit-progress.component'; import { HabitInviteFriendsComponent } from './components/habit/add-new-habit/habit-invite-friends/habit-invite-friends.component'; import { HabitDurationComponent } from './components/habit/add-new-habit/habit-duration/habit-duration.component'; -import { HabitEditShoppingListComponent } from './components/habit/add-new-habit/habit-edit-shopping-list/habit-edit-shopping-list.component'; +import { HabitEditToDoListComponent } from './components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component'; import { AddNewHabitComponent } from './components/habit/add-new-habit/add-new-habit.component'; import { GradientDirective } from './components/habit/add-new-habit/habit-duration/gradient.directive'; import { FriendDashboardComponent } from './components/profile/users-friends/friend-dashboard/friend-dashboard.component'; @@ -119,7 +119,7 @@ import { AchievementItemComponent } from './components/profile/users-achievement ProfileProgressComponent, ProfileComponent, EcoPlacesComponent, - ShoppingListComponent, + ToDoListComponent, CalendarComponent, EditProfileComponent, PersonalPhotoComponent, @@ -133,7 +133,7 @@ import { AchievementItemComponent } from './components/profile/users-achievement HabitProgressComponent, HabitInviteFriendsComponent, HabitDurationComponent, - HabitEditShoppingListComponent, + HabitEditToDoListComponent, GradientDirective, FriendDashboardComponent, AllFriendsComponent, diff --git a/src/app/main/model/goal/HabitAssignCustomPropertiesDto.ts b/src/app/main/model/goal/HabitAssignCustomPropertiesDto.ts index 6e7d069730..1f3af908dd 100644 --- a/src/app/main/model/goal/HabitAssignCustomPropertiesDto.ts +++ b/src/app/main/model/goal/HabitAssignCustomPropertiesDto.ts @@ -1,13 +1,13 @@ -import { CustomShoppingItem } from '@global-user/models/shoppinglist.interface'; +import { CustomToDoItem } from '@global-user/models/to-do-list.interface'; export interface HabitAssignCustomPropertiesDto { friendsIdsList: Array; habitAssignPropertiesDto: HabitAssignPropertiesDto; - customShoppingListItemList: Array; + customToDoListItemList: Array; } export interface HabitAssignPropertiesDto { - defaultShoppingListItems: Array; + defaultToDoListItems: Array; duration: number; isPrivate: boolean; } diff --git a/src/app/main/service/habit-assign/habit-assign.service.spec.ts b/src/app/main/service/habit-assign/habit-assign.service.spec.ts index ffb68b18bd..2ad6a7f794 100644 --- a/src/app/main/service/habit-assign/habit-assign.service.spec.ts +++ b/src/app/main/service/habit-assign/habit-assign.service.spec.ts @@ -109,11 +109,11 @@ describe('HabitService', () => { const HABIT_ASSIGN_CUSTOM: HabitAssignCustomPropertiesDto = { friendsIdsList: [2, 3, 4], habitAssignPropertiesDto: { - defaultShoppingListItems: [], + defaultToDoListItems: [], duration: 15, isPrivate: true }, - customShoppingListItemList: [{ text: '1234567890' }] + customToDoListItemList: [{ text: '1234567890' }] }; const spy = spyOn(service, 'assignCustomHabit'); diff --git a/src/app/main/service/habit/habit.service.spec.ts b/src/app/main/service/habit/habit.service.spec.ts index 28e82f35b8..3d3fab39b8 100644 --- a/src/app/main/service/habit/habit.service.spec.ts +++ b/src/app/main/service/habit/habit.service.spec.ts @@ -20,8 +20,8 @@ import { MOCK_CUSTOM_HABIT_RESPONSE, MOCK_FRIEND_PROFILE_PICTURES, MOCK_HABITS, - SHOPLIST -} from '@global-user/components/habit/mocks/shopping-list-mock'; + TODOLIST +} from '@global-user/components/habit/mocks/to-do-list-mock'; import { TAGLIST } from '@global-user/components/habit/mocks/tags-list-mock'; import { HttpParams, HttpResponse } from '@angular/common/http'; @@ -96,16 +96,16 @@ describe('HabitService', () => { req.flush(CUSTOMHABIT); }); - it('should return habit shopping list', () => { - habitService.getHabitShoppingList(2).subscribe((data) => { - expect(data).toBe(SHOPLIST); + it('should return habit toDo list', () => { + habitService.getHabitToDoList(2).subscribe((data) => { + expect(data).toBe(TODOLIST); }); - const req = httpMock.expectOne(`${habitLink}/2/shopping-list?lang=en`); + const req = httpMock.expectOne(`${habitLink}/2/to-do-list?lang=en`); expect(req.cancelled).toBeFalsy(); expect(req.request.responseType).toEqual('json'); expect(req.request.method).toBe('GET'); - req.flush(SHOPLIST); + req.flush(TODOLIST); }); it('should return habit tags', () => { diff --git a/src/app/main/service/habit/habit.service.ts b/src/app/main/service/habit/habit.service.ts index 084c3de7d5..abae933d90 100644 --- a/src/app/main/service/habit/habit.service.ts +++ b/src/app/main/service/habit/habit.service.ts @@ -7,7 +7,7 @@ import { habitLink } from '../../links'; import { TagInterface } from '@shared/components/tag-filter/tag-filter.model'; import { environment } from '@environment/environment'; import { HabitInterface, HabitListInterface } from '@global-user/components/habit/models/interfaces/habit.interface'; -import { ShoppingList } from '@global-user/models/shoppinglist.interface'; +import { ToDoList } from '@global-user/models/to-do-list.interface'; import { CustomHabitDtoRequest, CustomHabit } from '@global-user/components/habit/models/interfaces/custom-habit.interface'; import { FriendProfilePicturesArrayModel } from '@global-user/models/friend.model'; import { FileHandle } from '@eco-news-models/create-news-interface'; @@ -54,8 +54,8 @@ export class HabitService { return this.http.get(`${habitLink}/${id}?lang=${this.language}`); } - getHabitShoppingList(id: number): Observable> { - return this.http.get>(`${habitLink}/${id}/shopping-list?lang=${this.language}`); + getHabitToDoList(id: number): Observable> { + return this.http.get>(`${habitLink}/${id}/to-do-list?lang=${this.language}`); } getAllTags(): Observable> { @@ -97,7 +97,7 @@ export class HabitService { complexity: habit.complexity, defaultDuration: habit.duration, tagIds: habit.tagIds, - customShoppingListItemDto: habit.shopList + customToDoListItemDto: habit.toDoList }; const formData = new FormData(); diff --git a/src/assets/mocks/events/mock-events.ts b/src/assets/mocks/events/mock-events.ts index ec14474d16..1fb4472e9d 100644 --- a/src/assets/mocks/events/mock-events.ts +++ b/src/assets/mocks/events/mock-events.ts @@ -100,7 +100,7 @@ export const mockHabitAssign: HabitAssignInterface[] = [ habitStreak: 10, lastEnrollmentDate: new Date(), habitStatusCalendarDtoList: [], - shoppingListItems: [] + toDoListItems: [] }, { id: 2, @@ -115,7 +115,7 @@ export const mockHabitAssign: HabitAssignInterface[] = [ habitStreak: 10, lastEnrollmentDate: new Date(), habitStatusCalendarDtoList: [], - shoppingListItems: [] + toDoListItems: [] } ]; diff --git a/src/assets/mocks/habit/mock-habit-calendar.ts b/src/assets/mocks/habit/mock-habit-calendar.ts index e9c1825172..f34771b57d 100644 --- a/src/assets/mocks/habit/mock-habit-calendar.ts +++ b/src/assets/mocks/habit/mock-habit-calendar.ts @@ -10,7 +10,7 @@ export const mockHabits = { workingDays: 2, habitStreak: 10, habit: { - shoppingListItems: [{ id: 1, status: 'INPROGRESS', text: 'text', selected: true, custom: true }] + toDoListItems: [{ id: 1, status: 'INPROGRESS', text: 'text', selected: true, custom: true }] } }; From 1ae5e0f9a6c1d38b135505c09ca271e82af2be12 Mon Sep 17 00:00:00 2001 From: Tadei-Mykola Date: Wed, 6 Nov 2024 15:46:09 +0200 Subject: [PATCH 2/3] update en.json and ua.json --- src/assets/i18n/en.json | 3 +-- src/assets/i18n/ua.json | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index cc9e583f95..03b5831b56 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -806,7 +806,6 @@ "privacy": "Profile privacy", "location": "Show my location", "eco-place": "Show my eco places", - "shopping-list": "Show my shopping list", "to-do-list": "Show my To-do list", "picture-tooltip": "Upload PNG or JPG only. File size should be less than 10MB", "change-photo": "Do you want to change your profile picture?", @@ -920,7 +919,7 @@ }, "to-do": { "to-do-list": "To-do list", - "no-shopping-items": "No items to recommend", + "no-to-do-items": "No items to recommend", "too-long-input": "The input field should contain no more than 2048 characters", "add-custom-item": "Add custom item", "save": "Save", diff --git a/src/assets/i18n/ua.json b/src/assets/i18n/ua.json index b84e5b8a61..0d5550e3b3 100644 --- a/src/assets/i18n/ua.json +++ b/src/assets/i18n/ua.json @@ -816,7 +816,6 @@ "privacy": "Конфіденційність профілю", "location": "Показувати моє місцезнаходження", "eco-place": "Показувати мої еко-місця", - "shopping-list": "Показувати мій список покупок", "to-do-list": "Показувати мій список завдань", "picture-tooltip": "Завантажуйте лише PNG або JPEG. Розмір файлу не повинен перевищувати 10Mb", "change-photo": "Ви хочете змінити свою фотографію профілю?", @@ -930,7 +929,7 @@ }, "to-do": { "to-do-list": "Список завдань", - "no-shopping-items": "Не має елементів для рекомендації", + "no-to-do-items": "Не має елементів для рекомендації", "too-long-input": "Поле введення повинно містити не більше 2048 символів", "add-custom-item": "Додати власну річ", "save": "Зберегти", From 09da20cd8772e6ed5f862cdc552f518819a95d6d Mon Sep 17 00:00:00 2001 From: Tadei-Mykola Date: Wed, 6 Nov 2024 16:01:17 +0200 Subject: [PATCH 3/3] fix sonar --- .../habit-edit-to-do-list/habit-edit-to-do-list.component.ts | 3 +-- .../components/profile/to-do-list/to-do-list.component.html | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.ts b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.ts index 7e4b973218..688cc9571d 100644 --- a/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.ts +++ b/src/app/main/component/user/components/habit/add-new-habit/habit-edit-to-do-list/habit-edit-to-do-list.component.ts @@ -115,12 +115,11 @@ export class HabitEditToDoListComponent implements OnInit, OnChanges, OnDestroy selectItem(item: ToDoList): void { this.isListChanged = true; - this.toDoList.map((element) => { + this.toDoList.forEach((element) => { if (element.text === item.text) { element.selected = !item.selected; element.status = item.selected ? TodoStatus.inprogress : TodoStatus.active; } - return element; }); if (item.selected) { const index = this.toDoList.indexOf(item); diff --git a/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.html b/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.html index b4ccfba4f7..61a88fd3fa 100644 --- a/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.html +++ b/src/app/main/component/user/components/profile/to-do-list/to-do-list.component.html @@ -24,6 +24,7 @@