Skip to content

Commit 518f347

Browse files
committed
fix adding of contacts for edit project & fix criteria visual design
1 parent 2c8922f commit 518f347

7 files changed

Lines changed: 52 additions & 69 deletions

File tree

projects/social_platform/src/app/office/features/project-rating/project-rating.component.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
&__columns {
1212
display: flex;
1313
flex-direction: column;
14-
align-items: center;
1514
}
1615

1716
&__field {

projects/social_platform/src/app/office/program/shared/rating-card/rating-card.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<div class="card__naming">
1616
<a [routerLink]="['/office/projects/' + project.id]">
17-
<p class="text-body-12 card__naming--text">{{ project.name }}</p>
17+
<p class="text-body-12 card__naming--text">{{ project.name | truncate: 15 }}</p>
1818
</a>
1919

2020
@if (industryService.industries | async; as industries) { @if

projects/social_platform/src/app/office/program/shared/rating-card/rating-card.component.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
display: flex;
2626
gap: 20px;
2727
align-items: center;
28+
width: 100%;
2829
}
2930

3031
&__naming {

projects/social_platform/src/app/office/program/shared/rating-card/rating-card.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { ModalComponent } from "@ui/components/modal/modal.component";
4040
import { ProgramDataService } from "@office/program/services/program-data.service";
4141
import { AuthService } from "@auth/services";
4242
import { User } from "@auth/models/user.model";
43+
import { TruncatePipe } from "projects/core/src/lib/pipes/truncate.pipe";
4344

4445
/**
4546
* Компонент карточки оценки проекта
@@ -98,6 +99,7 @@ import { User } from "@auth/models/user.model";
9899
RouterLink,
99100
TagComponent,
100101
ModalComponent,
102+
TruncatePipe,
101103
],
102104
})
103105
export class RatingCardComponent implements OnInit, AfterViewInit, OnDestroy {

projects/social_platform/src/app/office/projects/edit/services/project-contacts.service.ts

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -71,45 +71,10 @@ export class ProjectContactsService {
7171
* @param linksFormArray FormArray, содержащий формы ссылок
7272
* @param projectForm основная форма проекта (FormGroup)
7373
*/
74-
public addLink(linksFormArray: FormArray, projectForm: FormGroup): void {
75-
// Инициализируем сигнал при первом вызове
74+
public addLink(linksFormArray: FormArray): void {
7675
this.initializeLinksItems(linksFormArray);
77-
78-
// Считываем вводимые данные
79-
const linkValue = projectForm.get("link")?.value;
80-
81-
// Проверяем, что поле не пустое и содержит валидный URL
82-
if (
83-
!linkValue ||
84-
!linkValue.trim() ||
85-
(!linkValue.includes("https://") && !linkValue.includes("http://"))
86-
) {
87-
return; // Выходим из функции, если поле пустое или невалидное
88-
}
89-
90-
const trimmedLink = linkValue.trim();
91-
92-
// Проверяем, редактируется ли существующая ссылка
93-
const editIdx = this.projectFormService.editIndex();
94-
if (editIdx !== null) {
95-
// Обновляем массив сигналов и соответствующий контрол в FormArray
96-
this.linksItems.update(items => {
97-
const updated = [...items];
98-
updated[editIdx] = trimmedLink.value;
99-
return updated;
100-
});
101-
linksFormArray.at(editIdx).patchValue(trimmedLink.value);
102-
// Сбрасываем индекс редактирования
103-
this.projectFormService.editIndex.set(null);
104-
} else {
105-
// Добавляем новую ссылку в сигнал и FormArray
106-
this.linksItems.update(items => [...items, trimmedLink.value]);
107-
linksFormArray.push(this.fb.control(trimmedLink, Validators.required));
108-
}
109-
110-
// Очищаем поле ввода формы проекта
111-
projectForm.get("link")?.reset();
112-
projectForm.get("link")?.setValue("");
76+
linksFormArray.push(this.fb.control("", Validators.required));
77+
this.linksItems.update(items => [...items, ""]);
11378
}
11479

11580
/**

projects/social_platform/src/app/office/projects/edit/shared/project-main-step/project-main-step.component.html

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -412,32 +412,41 @@
412412
</div>
413413

414414
<div [formGroup]="projectForm">
415-
@if (hasLinks) {
416-
<ul formArrayName="links" class="project__links--wrapper">
417-
@for (control of links.controls; track i; let i = $index) {
418-
<li class="project__links">
419-
<fieldset style="flex-grow: 1">
420-
<label class="text-body-12 field-label">ссылка на контакты и сообщества</label>
421-
<app-input
422-
size="big"
423-
[error]="links.at(i) | controlError"
424-
placeholder="@eeeasycarrer"
425-
[formControlName]="i"
426-
></app-input>
427-
@if (links.at(i) | controlError: "required") {
428-
<div class="text-body-10 error">
429-
{{ errorMessage.VALIDATION_REQUIRED }}
430-
</div>
431-
}
432-
</fieldset>
433-
<app-button class="project__links--remove" color="red" (click)="removeLink(i)" type="icon">
434-
<i appIcon icon="basket" appSquare="14"></i>
435-
</app-button>
436-
</li>
415+
<div formArrayName="links">
416+
@if (hasLinks) {
417+
<ul class="project__links--wrapper">
418+
@for (control of linksArray.controls; track trackByIndex($index)) {
419+
<li class="project__links">
420+
<fieldset style="flex-grow: 1">
421+
<label class="text-body-12 field-label">ссылка на контакты и сообщества</label>
422+
<app-input
423+
size="big"
424+
[formControlName]="$index"
425+
placeholder="@eeeasycarrer"
426+
></app-input>
427+
@if (control.invalid && (control.touched || projSubmitInitiated)) {
428+
<div class="text-body-10 error">
429+
{{ errorMessage.VALIDATION_REQUIRED }}
430+
</div>
431+
}
432+
</fieldset>
433+
434+
<app-button
435+
class="project__links--remove"
436+
color="red"
437+
(click)="removeLink($index)"
438+
type="icon"
439+
>
440+
<i appIcon icon="basket" appSquare="14"></i>
441+
</app-button>
442+
</li>
443+
}
444+
</ul>
437445
}
438-
</ul>
439-
}
446+
</div>
447+
<!-- ↑↑↑ formArrayName="links" закрывается здесь -->
440448

449+
<!-- Кнопка добавления -->
441450
<app-button
442451
(click)="addLink()"
443452
size="big"

projects/social_platform/src/app/office/projects/edit/shared/project-main-step/project-main-step.component.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class ProjectMainStepComponent implements OnInit, OnDestroy {
194194
* Проверяет, есть ли ссылки для отображения
195195
*/
196196
get hasLinks(): boolean {
197-
return this.links.length > 0;
197+
return this.linksArray.length > 0;
198198
}
199199

200200
/**
@@ -204,12 +204,15 @@ export class ProjectMainStepComponent implements OnInit, OnDestroy {
204204
return this.goals.length > 0;
205205
}
206206

207+
get linksArray(): FormArray {
208+
return this.projectForm.get("links") as FormArray;
209+
}
210+
207211
/**
208212
* Добавление ссылки
209213
*/
210-
addLink(link?: string): void {
211-
this.links.push(this.fb.control(link ?? "", [Validators.required]));
212-
this.projectContactsService.addLink(this.links, this.projectForm);
214+
addLink(): void {
215+
this.linksArray.push(this.fb.control("", Validators.required));
213216
}
214217

215218
/**
@@ -225,7 +228,7 @@ export class ProjectMainStepComponent implements OnInit, OnDestroy {
225228
* @param index - индекс ссылки
226229
*/
227230
removeLink(index: number): void {
228-
this.projectContactsService.removeLink(index, this.links);
231+
this.linksArray.removeAt(index);
229232
}
230233

231234
/**
@@ -309,4 +312,8 @@ export class ProjectMainStepComponent implements OnInit, OnDestroy {
309312
this.selectedLeaderId = "";
310313
}
311314
}
315+
316+
trackByIndex(index: number): number {
317+
return index;
318+
}
312319
}

0 commit comments

Comments
 (0)